Ejemplo n.º 1
0
        public IActionResult GoodsList(string category, int page = 1)
        {
            try
            {
                var laptopListViewModel = new LaptopListViewModel
                {
                    Laptops = goodsService.GetLaptopList()
                              .Where(p => category == null || p.Color == category)
                              .OrderBy(laptop => laptop.Id)
                              .Skip((page - 1) * pageSize)
                              .Take(pageSize).ToList(),

                    PagingInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        ItemsPerPage = pageSize,
                        TotalItems   = category == null?
                                       goodsService.GetLaptopList().Count : goodsService.GetLaptopList().Where(laptop => laptop.Color == category).Count()
                    },
                    CurrentCategory = category
                };
                return(View(laptopListViewModel));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public ViewResult List(string category)
        {
            string _category = category;
            IEnumerable <Laptop> llaptops = null;
            string laptopCategory         = "";

            if (string.IsNullOrEmpty(category))
            {
                llaptops = _allLaptop.Laptops.OrderBy(i => i.Id);
            }
            else
            {
                if (string.Equals("gaming", category, StringComparison.OrdinalIgnoreCase))
                {
                    llaptops       = _allLaptop.Laptops.Where(i => i.LaptopCategory.CategoryName.Equals("Игровой")).OrderBy(i => i.Id);
                    laptopCategory = "Игровой";
                }
                else if (string.Equals("business", category, StringComparison.OrdinalIgnoreCase))
                {
                    llaptops       = _allLaptop.Laptops.Where(i => i.LaptopCategory.CategoryName.Equals("Бизнес-ноутбук")).OrderBy(i => i.Id);
                    laptopCategory = "Бизнес-ноутбук";
                }
            }
            var laptopObject = new LaptopListViewModel
            {
                AllLaptops     = llaptops,
                LaptopCategory = laptopCategory,
            };

            ViewBag.Title = "Ноутбуки";
            return(View(laptopObject));
        }