public RedirectToRouteResult AddToCart(Cart cart, int?Id, string returnUrl) { ProductViewModel prod = _productViewService.ViewAll().FirstOrDefault(p => p.Id == Id); if (prod != null) { cart.AddItem(prod, 1); } return(RedirectToAction("Index", new { returnUrl })); }
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)); }
public ViewResult Index() { return(View(_productViewService.ViewAll())); }