public ActionResult Create(Product product) { Shop.CreateProduct(product.Name, product.Description, product.Price, product.Weight, product.Image); return RedirectToAction("Index"); }
public static Product CreateProduct(string name, string description, decimal price, decimal weight, string image) { using (var db = new ShopModel()) { var p = new Product { Name = name, Description = description, Weight = weight, Price = price, Image = image }; db.Products.Add(p); db.SaveChanges(); return p; } }
public static void UpdateProduct(Product updatedProduct) { using (var db = new ShopModel()) { var product = db.Products. Where(p => p.ProductId == updatedProduct.ProductId).FirstOrDefault(); if (product == null) return; var originalProduct = product; product.Name = updatedProduct.Name; product.Price = updatedProduct.Price; product.Weight = updatedProduct.Weight; product.Image = updatedProduct.Image; product.Description = updatedProduct.Description; db.Entry(originalProduct).CurrentValues.SetValues(product); db.SaveChanges(); } }
public static void DeleteProduct(Product product) { using (var db = new ShopModel()) { db.Products.Remove(product); db.SaveChanges(); } }
public ActionResult Delete(Product product) { Shop.DeleteProduct(product); return RedirectToAction("Index"); }
public ActionResult Edit(Product product) { Shop.UpdateProduct(product); return RedirectToAction("Index"); }