Esempio n. 1
0
        public ViewResult Edit(int?Id)
        {
            SelectList groups = new SelectList(_groupViewService.ViewAll(), "Id", "GroupName");

            ViewBag.Groups = groups;
            ProductViewModel product = Id != null?_productViewService.ViewSingle(Convert.ToInt32(Id.ToString())) : new ProductViewModel();

            return(View(product));
        }
        public ActionResult Index(int?category, int?group, Order sort = Order.not_sort, int page = 1)
        {
            IEnumerable <ProductViewModel> products = _productViewService.ViewAll().ToList().Where(c => category == null || c.ProductGroup.ProductCategoryid == category).
                                                      Where(g => group == null || g.ProductGroupId == group);
            PageInfo pageInfo = new PageInfo {
                PageNumber = page, PageSize = pageSize, TotalItems = products.Count()
            };

            switch (sort)
            {
            case Order.not_sort:
                products = products.OrderBy(C => C.Id).Skip((page - 1) * pageSize).Take(pageSize);
                break;

            case Order.first_expensive:
                products = products.OrderByDescending(C => C.Price).Skip((page - 1) * pageSize).Take(pageSize);
                break;

            case Order.first_cheap:
                products = products.OrderBy(C => C.Price).Skip((page - 1) * pageSize).Take(pageSize);
                break;
            }


            IndexProductViewModel ivm = new IndexProductViewModel
            {
                PageInfo        = pageInfo,
                Products        = products,
                CurrentCategory = _categoryViewService.ViewAll().Where(c => c.Id == category).FirstOrDefault(),
                CurrentGroup    = _groupViewService.ViewAll().Where(g => g.Id == group).FirstOrDefault(),
                CurrentOrder    = sort
            };


            return(View(ivm));
        }
Esempio n. 3
0
 public ViewResult Index()
 {
     return(View(_groupViewService.ViewAll()));
 }