Refactoring and Adding Tests (#28)
* Introducing repository and refactoring services. Changing entities to use int keys everywhere. * Refactoring application services to live in web project and only reference repositories, not EF contexts. * Cleaning up implementations * Moving logic out of CatalogController Moving entity knowledge out of viewmodels. * Implementing specification includes better for catalogservice * Cleaning up and adding specification unit tests
This commit is contained in:
@@ -29,23 +29,10 @@ namespace Microsoft.eShopWeb.Controllers
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
//var user = _appUserParser.Parse(HttpContext.User);
|
||||
var basket = await GetBasketFromSessionAsync();
|
||||
var basketModel = await GetBasketFromSessionAsync();
|
||||
|
||||
var viewModel = new BasketViewModel()
|
||||
{
|
||||
BuyerId = basket.BuyerId,
|
||||
Items = basket.Items.Select(i => new BasketItemViewModel()
|
||||
{
|
||||
Id = i.Id,
|
||||
UnitPrice = i.UnitPrice,
|
||||
PictureUrl = _uriComposer.ComposePicUri(i.Item.PictureUri),
|
||||
ProductId = i.Item.Id.ToString(),
|
||||
ProductName = i.Item.Name,
|
||||
Quantity = i.Quantity
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
return View(basketModel);
|
||||
}
|
||||
|
||||
// GET: /Cart/AddToCart
|
||||
@@ -58,23 +45,23 @@ namespace Microsoft.eShopWeb.Controllers
|
||||
}
|
||||
var basket = await GetBasketFromSessionAsync();
|
||||
|
||||
await _basketService.AddItemToBasket(basket, productDetails.Id, 1);
|
||||
await _basketService.AddItemToBasket(basket.Id, productDetails.Id, productDetails.Price, 1);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
private async Task<Basket> GetBasketFromSessionAsync()
|
||||
private async Task<BasketViewModel> GetBasketFromSessionAsync()
|
||||
{
|
||||
string basketId = HttpContext.Session.GetString(_basketSessionKey);
|
||||
Basket basket = null;
|
||||
BasketViewModel basket = null;
|
||||
if (basketId == null)
|
||||
{
|
||||
basket = await _basketService.CreateBasketForUser(User.Identity.Name);
|
||||
HttpContext.Session.SetString(_basketSessionKey, basket.Id);
|
||||
HttpContext.Session.SetString(_basketSessionKey, basket.Id.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
basket = await _basketService.GetBasket(basketId);
|
||||
basket = await _basketService.GetBasket(int.Parse(basketId));
|
||||
}
|
||||
return basket;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,21 @@
|
||||
using Microsoft.eShopWeb.Services;
|
||||
using Microsoft.eShopWeb.ViewModels;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationCore.Interfaces;
|
||||
|
||||
namespace Microsoft.eShopWeb.Controllers
|
||||
{
|
||||
public class CatalogController : Controller
|
||||
{
|
||||
private readonly IHostingEnvironment _env;
|
||||
private readonly ICatalogService _catalogService;
|
||||
private readonly IImageService _imageService;
|
||||
private readonly IAppLogger<CatalogController> _logger;
|
||||
|
||||
public CatalogController(IHostingEnvironment env,
|
||||
ICatalogService catalogService,
|
||||
IImageService imageService,
|
||||
IAppLogger<CatalogController> logger)
|
||||
{
|
||||
_env = env;
|
||||
_catalogService = catalogService;
|
||||
_imageService = imageService;
|
||||
_logger = logger;
|
||||
}
|
||||
public CatalogController(ICatalogService catalogService) => _catalogService = catalogService;
|
||||
|
||||
// GET: /<controller>/
|
||||
public async Task<IActionResult> Index(int? brandFilterApplied, int? typesFilterApplied, int? page)
|
||||
{
|
||||
var itemsPage = 10;
|
||||
var catalog = await _catalogService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied);
|
||||
|
||||
var vm = new CatalogIndex()
|
||||
{
|
||||
CatalogItems = catalog.Data,
|
||||
Brands = await _catalogService.GetBrands(),
|
||||
Types = await _catalogService.GetTypes(),
|
||||
BrandFilterApplied = brandFilterApplied ?? 0,
|
||||
TypesFilterApplied = typesFilterApplied ?? 0,
|
||||
PaginationInfo = new PaginationInfo()
|
||||
{
|
||||
ActualPage = page ?? 0,
|
||||
ItemsPerPage = catalog.Data.Count,
|
||||
TotalItems = catalog.Count,
|
||||
TotalPages = int.Parse(Math.Ceiling(((decimal)catalog.Count / itemsPage)).ToString())
|
||||
}
|
||||
};
|
||||
|
||||
vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
|
||||
vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
|
||||
|
||||
return View(vm);
|
||||
var catalogModel = await _catalogService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied);
|
||||
return View(catalogModel);
|
||||
}
|
||||
|
||||
public IActionResult Error()
|
||||
|
||||
14
src/Web/Interfaces/IBasketService.cs
Normal file
14
src/Web/Interfaces/IBasketService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.eShopWeb.ViewModels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketViewModel> GetBasket(int basketId);
|
||||
Task<BasketViewModel> CreateBasket();
|
||||
Task<BasketViewModel> CreateBasketForUser(string userId);
|
||||
|
||||
Task AddItemToBasket(int basketId, int catalogItemId, decimal price, int quantity);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Microsoft.eShopWeb.Services
|
||||
{
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? brandID, int? typeId);
|
||||
Task<CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId);
|
||||
Task<IEnumerable<SelectListItem>> GetBrands();
|
||||
Task<IEnumerable<SelectListItem>> GetTypes();
|
||||
}
|
||||
|
||||
86
src/Web/Services/BasketService.cs
Normal file
86
src/Web/Services/BasketService.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using ApplicationCore.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using Infrastructure.Data;
|
||||
using System.Linq;
|
||||
using Microsoft.eShopWeb.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using ApplicationCore.Specifications;
|
||||
|
||||
namespace Web.Services
|
||||
{
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
private readonly IRepository<Basket> _basketRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly IRepository<CatalogItem> _itemRepository;
|
||||
|
||||
public BasketService(IRepository<Basket> basketRepository,
|
||||
IRepository<CatalogItem> itemRepository,
|
||||
IUriComposer uriComposer)
|
||||
{
|
||||
_basketRepository = basketRepository;
|
||||
_uriComposer = uriComposer;
|
||||
_itemRepository = itemRepository;
|
||||
}
|
||||
public async Task<BasketViewModel> GetBasket(int basketId)
|
||||
{
|
||||
var basketSpec = new BasketWithItemsSpecification(basketId);
|
||||
var basket = _basketRepository.List(basketSpec).FirstOrDefault();
|
||||
if (basket == null)
|
||||
{
|
||||
return await CreateBasket();
|
||||
}
|
||||
|
||||
var viewModel = new BasketViewModel();
|
||||
viewModel.Id = basket.Id;
|
||||
viewModel.BuyerId = basket.BuyerId;
|
||||
viewModel.Items = basket.Items.Select(i =>
|
||||
{
|
||||
var itemModel = new BasketItemViewModel()
|
||||
{
|
||||
Id = i.Id,
|
||||
UnitPrice = i.UnitPrice,
|
||||
Quantity = i.Quantity,
|
||||
CatalogItemId = i.CatalogItemId
|
||||
|
||||
};
|
||||
var item = _itemRepository.GetById(i.CatalogItemId);
|
||||
itemModel.PictureUrl = _uriComposer.ComposePicUri(item.PictureUri);
|
||||
itemModel.ProductName = item.Name;
|
||||
return itemModel;
|
||||
})
|
||||
.ToList();
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public Task<BasketViewModel> CreateBasket()
|
||||
{
|
||||
return CreateBasketForUser(null);
|
||||
}
|
||||
|
||||
public async Task<BasketViewModel> CreateBasketForUser(string userId)
|
||||
{
|
||||
var basket = new Basket() { BuyerId = userId };
|
||||
_basketRepository.Add(basket);
|
||||
|
||||
return new BasketViewModel()
|
||||
{
|
||||
BuyerId = basket.BuyerId,
|
||||
Id = basket.Id,
|
||||
Items = new List<BasketItemViewModel>()
|
||||
};
|
||||
}
|
||||
|
||||
public async Task AddItemToBasket(int basketId, int catalogItemId, decimal price, int quantity)
|
||||
{
|
||||
var basket = _basketRepository.GetById(basketId);
|
||||
|
||||
basket.AddItem(catalogItemId, price, quantity);
|
||||
|
||||
_basketRepository.Update(basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Microsoft.eShopWeb.Services
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? brandID, int? typeId)
|
||||
public async Task<CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int? brandID, int? typeId)
|
||||
{
|
||||
string cacheKey = String.Format(_itemsKeyTemplate, pageIndex, itemsPage, brandID, typeId);
|
||||
return await _cache.GetOrCreateAsync(cacheKey, async entry =>
|
||||
|
||||
@@ -2,84 +2,88 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.eShopWeb.ViewModels;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Data.SqlClient;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Infrastructure.Data;
|
||||
using ApplicationCore.Interfaces;
|
||||
using System;
|
||||
using ApplicationCore.Specifications;
|
||||
|
||||
namespace Microsoft.eShopWeb.Services
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly CatalogContext _context;
|
||||
private readonly IOptionsSnapshot<CatalogSettings> _settings;
|
||||
private readonly ILogger<CatalogService> _logger;
|
||||
|
||||
public CatalogService(CatalogContext context,
|
||||
IOptionsSnapshot<CatalogSettings> settings,
|
||||
ILoggerFactory loggerFactory)
|
||||
private readonly IRepository<CatalogItem> _itemRepository;
|
||||
private readonly IRepository<CatalogBrand> _brandRepository;
|
||||
private readonly IRepository<CatalogType> _typeRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
|
||||
public CatalogService(
|
||||
ILoggerFactory loggerFactory,
|
||||
IRepository<CatalogItem> itemRepository,
|
||||
IRepository<CatalogBrand> brandRepository,
|
||||
IRepository<CatalogType> typeRepository,
|
||||
IUriComposer uriComposer)
|
||||
{
|
||||
_context = context;
|
||||
_settings = settings;
|
||||
_logger = loggerFactory.CreateLogger<CatalogService>();
|
||||
_itemRepository = itemRepository;
|
||||
_brandRepository = brandRepository;
|
||||
_typeRepository = typeRepository;
|
||||
_uriComposer = uriComposer;
|
||||
}
|
||||
|
||||
public async Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId)
|
||||
public async Task<CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId)
|
||||
{
|
||||
_logger.LogInformation("GetCatalogItems called.");
|
||||
var root = (IQueryable<CatalogItem>)_context.CatalogItems;
|
||||
|
||||
if (typeId.HasValue)
|
||||
{
|
||||
root = root.Where(ci => ci.CatalogTypeId == typeId);
|
||||
}
|
||||
var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
|
||||
var root = _itemRepository.List(filterSpecification);
|
||||
|
||||
if (brandId.HasValue)
|
||||
{
|
||||
root = root.Where(ci => ci.CatalogBrandId == brandId);
|
||||
}
|
||||
var totalItems = root.Count();
|
||||
|
||||
var totalItems = await root
|
||||
.LongCountAsync();
|
||||
|
||||
var itemsOnPage = await root
|
||||
var itemsOnPage = root
|
||||
.Skip(itemsPage * pageIndex)
|
||||
.Take(itemsPage)
|
||||
.ToListAsync();
|
||||
.ToList();
|
||||
|
||||
itemsOnPage = ComposePicUri(itemsOnPage);
|
||||
itemsOnPage.ForEach(x =>
|
||||
{
|
||||
x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
|
||||
});
|
||||
|
||||
return new Catalog() { Data = itemsOnPage, PageIndex = pageIndex, Count = (int)totalItems };
|
||||
var vm = new CatalogIndexViewModel()
|
||||
{
|
||||
CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
|
||||
{
|
||||
Id = i.Id,
|
||||
Name = i.Name,
|
||||
PictureUri = i.PictureUri,
|
||||
Price = i.Price
|
||||
}),
|
||||
Brands = await GetBrands(),
|
||||
Types = await GetTypes(),
|
||||
BrandFilterApplied = brandId ?? 0,
|
||||
TypesFilterApplied = typeId ?? 0,
|
||||
PaginationInfo = new PaginationInfoViewModel()
|
||||
{
|
||||
ActualPage = pageIndex,
|
||||
ItemsPerPage = itemsOnPage.Count,
|
||||
TotalItems = totalItems,
|
||||
TotalPages = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
|
||||
}
|
||||
};
|
||||
|
||||
vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
|
||||
vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SelectListItem>> GetBrands()
|
||||
{
|
||||
_logger.LogInformation("GetBrands called.");
|
||||
var brands = await _context.CatalogBrands.ToListAsync();
|
||||
|
||||
//// create
|
||||
//var newBrand = new CatalogBrand() { Brand = "Acme" };
|
||||
//_context.Add(newBrand);
|
||||
//await _context.SaveChangesAsync();
|
||||
|
||||
//// read and update
|
||||
//var existingBrand = _context.Find<CatalogBrand>(1);
|
||||
//existingBrand.Brand = "Updated Brand";
|
||||
//await _context.SaveChangesAsync();
|
||||
|
||||
//// delete
|
||||
//var brandToDelete = _context.Find<CatalogBrand>(2);
|
||||
//_context.CatalogBrands.Remove(brandToDelete);
|
||||
//await _context.SaveChangesAsync();
|
||||
|
||||
//var brandsWithItems = await _context.CatalogBrands
|
||||
// .Include(b => b.Items)
|
||||
// .ToListAsync();
|
||||
|
||||
var brands = _brandRepository.List();
|
||||
|
||||
var items = new List<SelectListItem>
|
||||
{
|
||||
@@ -96,7 +100,7 @@ namespace Microsoft.eShopWeb.Services
|
||||
public async Task<IEnumerable<SelectListItem>> GetTypes()
|
||||
{
|
||||
_logger.LogInformation("GetTypes called.");
|
||||
var types = await _context.CatalogTypes.ToListAsync();
|
||||
var types = _typeRepository.List();
|
||||
var items = new List<SelectListItem>
|
||||
{
|
||||
new SelectListItem() { Value = null, Text = "All", Selected = true }
|
||||
@@ -108,27 +112,5 @@ namespace Microsoft.eShopWeb.Services
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<CatalogItem> ComposePicUri(List<CatalogItem> items)
|
||||
{
|
||||
var baseUri = _settings.Value.CatalogBaseUrl;
|
||||
items.ForEach(x =>
|
||||
{
|
||||
x.PictureUri = x.PictureUri.Replace("http://catalogbaseurltobereplaced", baseUri);
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
//public async Task<IEnumerable<CatalogType>> GetCatalogTypes()
|
||||
//{
|
||||
// return await _context.CatalogTypes.ToListAsync();
|
||||
//}
|
||||
|
||||
//private readonly SqlConnection _conn;
|
||||
//public async Task<IEnumerable<CatalogType>> GetCatalogTypesWithDapper()
|
||||
//{
|
||||
// return await _conn.QueryAsync<CatalogType>("SELECT * FROM CatalogType");
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace Microsoft.eShopWeb
|
||||
.AddEntityFrameworkStores<AppIdentityDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
|
||||
services.AddMemoryCache();
|
||||
services.AddScoped<ICatalogService, CachedCatalogService>();
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
@@ -93,9 +95,7 @@ namespace Microsoft.eShopWeb
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app,
|
||||
IHostingEnvironment env,
|
||||
ILoggerFactory loggerFactory,
|
||||
UserManager<ApplicationUser> userManager)
|
||||
IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
@@ -139,6 +139,15 @@ namespace Microsoft.eShopWeb
|
||||
template: "{controller=Catalog}/{action=Index}/{id?}");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void ConfigureDevelopment(IApplicationBuilder app,
|
||||
IHostingEnvironment env,
|
||||
ILoggerFactory loggerFactory,
|
||||
UserManager<ApplicationUser> userManager)
|
||||
{
|
||||
Configure(app, env);
|
||||
|
||||
//Seed Data
|
||||
CatalogContextSeed.SeedAsync(app, loggerFactory)
|
||||
.Wait();
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
|
||||
public class BasketItemViewModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string ProductId { get; set; }
|
||||
public int Id { get; set; }
|
||||
public int CatalogItemId { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public decimal OldUnitPrice { get; set; }
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Microsoft.eShopWeb.ViewModels
|
||||
|
||||
public class BasketViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public List<BasketItemViewModel> Items { get; set; } = new List<BasketItemViewModel>();
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
public class Catalog
|
||||
{
|
||||
public int PageIndex { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<CatalogItem> Data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
public class CatalogIndex
|
||||
public class CatalogIndexViewModel
|
||||
{
|
||||
public IEnumerable<CatalogItem> CatalogItems { get; set; }
|
||||
public IEnumerable<CatalogItemViewModel> CatalogItems { get; set; }
|
||||
public IEnumerable<SelectListItem> Brands { get; set; }
|
||||
public IEnumerable<SelectListItem> Types { get; set; }
|
||||
public int? BrandFilterApplied { get; set; }
|
||||
public int? TypesFilterApplied { get; set; }
|
||||
public PaginationInfo PaginationInfo { get; set; }
|
||||
public PaginationInfoViewModel PaginationInfo { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Web/ViewModels/CatalogItemViewModel.cs
Normal file
14
src/Web/ViewModels/CatalogItemViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
|
||||
public class CatalogItemViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string PictureUri { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
namespace Microsoft.eShopWeb.ViewModels
|
||||
{
|
||||
public class PaginationInfo
|
||||
public class PaginationInfoViewModel
|
||||
{
|
||||
public int TotalItems { get; set; }
|
||||
public int ItemsPerPage { get; set; }
|
||||
@@ -1,6 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Catalog";
|
||||
@model Microsoft.eShopWeb.ViewModels.CatalogIndex
|
||||
@model CatalogIndexViewModel
|
||||
}
|
||||
<section class="esh-catalog-hero">
|
||||
<div class="container">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model Microsoft.eShopWeb.ViewModels.PaginationInfo
|
||||
@model PaginationInfoViewModel
|
||||
|
||||
<div class="esh-pager">
|
||||
<div class="container">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem
|
||||
@model CatalogItemViewModel
|
||||
|
||||
|
||||
<form asp-controller="Cart" asp-action="AddToCart">
|
||||
@@ -12,11 +12,11 @@
|
||||
<div class="esh-catalog-price">
|
||||
<span>@Model.Price.ToString("N2")</span>
|
||||
</div>
|
||||
<input type="hidden" asp-for="@Model.CatalogBrand" name="brand" />
|
||||
@*<input type="hidden" asp-for="@Model.CatalogBrand" name="brand" />
|
||||
<input type="hidden" asp-for="@Model.CatalogBrandId" name="brandId" />
|
||||
<input type="hidden" asp-for="@Model.CatalogType" name="type" />
|
||||
<input type="hidden" asp-for="@Model.CatalogTypeId" name="typeId" />
|
||||
<input type="hidden" asp-for="@Model.Description" name="description" />
|
||||
<input type="hidden" asp-for="@Model.Description" name="description" />*@
|
||||
<input type="hidden" asp-for="@Model.Id" name="id" />
|
||||
<input type="hidden" asp-for="@Model.Name" name="name" />
|
||||
<input type="hidden" asp-for="@Model.PictureUri" name="pictureUri" />
|
||||
|
||||
Reference in New Issue
Block a user