public ActionResult Delete(int id, Product product) { try { var db = new CRUDExample(); var model = (from p in db.Product where p.Id == id select p).FirstOrDefault(); if (model != null) { db.Product.Remove(model); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(Product product) { try { var db = new CRUDExample(); var model = new Entity.Product(); if (model != null) { model.Name = product.Name; db.Product.Add(model); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Delete(int id, Product product) { try { var db = new CRUDExample(); var model = (from p in db.Product where p.Id == id select p).FirstOrDefault(); if (model != null) { db.Product.Remove(model); db.SaveChanges(); } return RedirectToAction("Index"); } catch { // Set our navigation again, or it will be lost - these values disappear // on each request and need to be restored if we go back to the same view. var node1 = SiteMaps.Current.FindSiteMapNodeFromKey("Product_Delete"); if (node1 != null) { // Set the id of the Edit node node1.RouteValues["id"] = id; var parent = node1.ParentNode; if (parent != null) { // Set the id of the Details node parent.RouteValues["id"] = id; } } return View(); } }
public ActionResult Edit(int productId, Product product) { try { var db = new CRUDExample(); var model = (from p in db.Product where p.Id == productId select p).FirstOrDefault(); if (model != null) { model.Name = product.Name; db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, Product product) { try { var db = new CRUDExample(); var model = (from p in db.Product where p.Id == id select p).FirstOrDefault(); if (model != null) { model.Name = product.Name; db.SaveChanges(); } return RedirectToAction("Index"); } catch { // Set our navigation again, or it will be lost - these values disappear // on each request and need to be restored if we go back to the same view. var node1 = SiteMaps.Current.FindSiteMapNodeFromKey("Product_Edit"); if (node1 != null) { // Set the id of the Edit node node1.RouteValues["id"] = id; var parent = node1.ParentNode; if (parent != null) { // Set the id of the Details node parent.RouteValues["id"] = id; // Set the title and description of the Details node based on postback data parent.Title = product.Name; parent.Description = product.Name; } // Set a custom attribute - we can set this to any object node1.Attributes["CustomKey"] = "SomeCustomValue"; } return View(); } }