public ActionResult Create(Product product) { try { // TODO: Add insert logic here if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return RedirectToAction("Index"); } return View(product); } catch { return View(product); } }
public ActionResult Edit(Product product) { try { // TODO: Add update logic here if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(product); } catch { return View(product); } }
public ActionResult Delete(int id, Product product) { try { // TODO: Add delete logic here if (ModelState.IsValid) { product = db.Products.Find(id); if(product == null) { return HttpNotFound(); } db.Products.Remove(product); db.SaveChanges(); return RedirectToAction("Index"); } return View(product); } catch { return View(product); } }