예제 #1
0
        public ViewResult List(int?page, string category, string Filter_Value)
        {
            if (category != null)
            {
                page = 1;
            }
            else
            {
                category = Filter_Value;
            }
            ViewBag.FilterValue = category;
            ProductListViewModel model = new ProductListViewModel
            {
                Prodcuts = repository.Products
                           .Where(p => category == null || p.Category == category),
                CurrentCategory = category
            };

            return(View(model.Prodcuts.ToList().ToPagedList(page ?? 1, 3)));
        }
        // GET: Product
        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),
                PageInfo = new PageInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = category == null?
                                   repository.Products.Count() :
                                       repository.Products.Where(p => p.Category == category).Count()
                },
                CurrentCategory = category
            };

            return(View(model));
        }