public ViewResult List(string category, int page = 1) { ProductsListViewModel model = new ProductsListViewModel { Products = repository.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductId) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(p => p.Category == category).Count() }, CurrentCategory = category }; return View(model); }
public ViewResult List_Furniture(int page = 1) { ProductsListViewModel model = new ProductsListViewModel { Products = repository.Products .Where(p => p.Category == "Furniture") .OrderBy(p => p.ProductId) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Where(p => p.Category == "Furniture").Count() }, CurrentCategory = "Furniture" }; return View(model); }