예제 #1
0
 public ActionResult Create()
 {
     var model = new Products { Image = "/gallery/Image_Not_Found.jpg" };
     CategoryDropDownList();
     StatusDropDownList();
     return View(model);
 }
예제 #2
0
파일: Cart.cs 프로젝트: Rocket18/WebStore
 public void AddItem(Products product, int quantity)
 {
     CartLine line = lineCollection
         .Where(p => p.Product.ProductID == product.ProductID)
         .FirstOrDefault();
     if (line == null)
     {
         lineCollection.Add(new CartLine
         {
             Product = product,
             Quantity = quantity
         });
     }
     else
     {
         line.Quantity = quantity;
     }
 }
예제 #3
0
파일: Cart.cs 프로젝트: Rocket18/WebStore
 public void RemoveLine(Products product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }
예제 #4
0
        private void UpdateProductCategory(string[] selectedCategories, Products DBproduct)
        {
            if (selectedCategories == null)
            {
                DBproduct.Categories = new List<Categories>();
                return;
            }

            var selectedCategoriesHS = new HashSet<string>(selectedCategories);
            var productCategory = new HashSet<int>(DBproduct.Categories.Select(c => c.CategoryID));

            foreach (var cat in repository.Categories.GetAll())
            {
                if (selectedCategoriesHS.Contains(cat.CategoryID.ToString()))
                {
                    if (!productCategory.Contains(cat.CategoryID))
                    {
                        DBproduct.Categories.Add(cat);
                    }
                }
                else
                {
                    if (productCategory.Contains(cat.CategoryID))
                    {
                        DBproduct.Categories.Remove(cat);
                    }
                }
            }
        }
예제 #5
0
 public ActionResult Edit(Products product, string[] selectedCategories)
 {
     var DBproduct = repository.Products.GetAll(includeProperties: "Categories", filter: p => p.ProductID == product.ProductID).SingleOrDefault();
     if (ModelState.IsValid)
     {
         TryUpdateModel(DBproduct, "",new string[] { "Name", "Image", "Price", "Avilability", "Company" });
         UpdateProductCategory(selectedCategories, DBproduct);
         repository.Products.Update(DBproduct);
         repository.Save();
         return RedirectToAction("Index");
     }
     else
     {
         StatusDropDownList();
         CategoryDropDownList();
         return View(product);
     }
 }