public ViewResult List(string category, int page = 1) { ProductsListViewModel model = new Models.ProductsListViewModel(); model.Products = _repository.Product .Where(p => p.Category.Trim() == category || category == null) .OrderBy(p => p.Price) .Skip((page - 1) * pageSize) .Take(pageSize); model.PagingInfo = new Models.PagingInfo() { TotalItems = _repository.Product .Where(p => p.Category.Trim() == category || category == null) .Count(), ItemPerPage = pageSize, CurrentPage = page }; model.CurrentCategory = category; ViewBag.CurrentCategory = category; return(View(model)); }
// GET: Product public ViewResult List(string category, int page = 1) { ProductsListViewModel model = new Models.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(e => e.Category == category).Count() }, CurrentCategory = category }; return(View(model)); //return View(repository.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize)); }