public ViewResult Index(string category = null, int page = 1) { ProductsListViewModel viewModel = new ProductsListViewModel { Products = repository.Products .OrderBy(x => x.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PageInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(x => x.Category == category).Count() } }; return View(viewModel); }
public async Task<ViewResult> List(string category, int page = 1) { IEnumerable<Product> products = await repository.GetProductsByCategory(category); ProductsListViewModel model = new ProductsListViewModel { Products = products, PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = products.Count() }, CurrentCategory = category }; return View(model); }