示例#1
0
        public RedirectToRouteResult AddToCart(int Id, string returnUrl)
        {
            Product product = _productManger.GettAll()
                              .FirstOrDefault(p => p.Id == Id);

            if (product != null)
            {
                GetCart().AddItem(product, 1);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
        public ActionResult List(string CategoryName)
        {
            List <Product>        Mylist = new List <Product>();
            ProductsListViewModel model  = new ProductsListViewModel();

            if (CategoryName == null)
            {
                Mylist         = _productManger.GettAll().Where(p => p.IsArchived == false && p.Category.HiddInMenu == false).ToList();
                model.Products = Mylist;
            }
            else
            {
                Mylist = _productManger.GettAll().Where(p =>
                                                        p.Category.Name == CategoryName &&
                                                        p.IsArchived == false &&
                                                        p.Category.HiddInMenu == false).ToList();
                model.Products = Mylist;
            }

            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = _CategoryManger.GetBy(id);

            category.IsArchived = true;
            category.HiddInMenu = true;
            List <Product> MyProductList = new List <Product>();

            MyProductList = _ProductManger.GettAll().Where(c => c.CategoryId == category.Id).ToList();
            foreach (var item in MyProductList)
            {
                item.IsArchived = true;
            }
            _ProductManger.Save();
            _CategoryManger.Save();
            return(RedirectToAction("Index"));
        }