public ActionResult Create() { var model = new Products { Image = "/gallery/Image_Not_Found.jpg" }; CategoryDropDownList(); StatusDropDownList(); return View(model); }
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; } }
public void RemoveLine(Products product) { lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID); }
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); } } } }
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); } }