Esempio n. 1
0
        public ActionResult SearchList(string category,  int page = 1)
        {
            IEnumerable<Product> products = (IEnumerable<Product>)TempData["Products"];
            if (products == null)
                return RedirectToAction("List");
            pagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = products.Count() };

            logger.Info("List");

            ProductListViewModel viewModel = new ProductListViewModel
            {
                Products = products,
                PagingInfo = pagingInfo
            };
            currentCategory = category;
            viewModel.CurrentCategory = category;
            return View("List", viewModel);
        }
Esempio n. 2
0
        public ViewResult List(string category, int page = 1)
        {
            productsOfCategory = repository.Products.Where(p => category == null || p.Category.CategoryName == category);
            productsForDisplay = productsOfCategory.OrderBy(x => x.ProductID).Skip((page - 1) * PageSize).Take(PageSize);

            pagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = productsOfCategory.Count() };

            logger.Info("List");

            ProductListViewModel viewModel = new ProductListViewModel
            {
                Products = productsForDisplay,
                PagingInfo = pagingInfo
            };
            currentCategory = category;
            viewModel.CurrentCategory = category;
            return View(viewModel);
        }
 public ViewResult List(string category,int page=1)
 {
     ProductListViewModel model = new ProductListViewModel
     {
         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,
             ItemPerPage = pageSize,
             TotalItems = category == null ?
             repository.Products.Count() :
             repository.Products.Where(p => p.Category == category).Count()
         },
         CurrentCategory=category
     };
     return View(model);
 }