Esempio n. 1
0
        public ViewResult List(int page = 1, string category = null)
        {
            var products = category == null
                ? _productsRepo.Query
                : _productsRepo.Query.Where(p => p.Category == category);

            var model = new ProductListViewModel
            {
                Products = products
                    .Skip((page - 1) * PageSize)
                    .Take(PageSize)
                    .ToList(),
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    ItemsPerPage = PageSize,
                    TotalItems = products.Count()
                },
                CurrentCategory = category
            };

            return View(model);
        }