public ActionResult Delete(int id) { var db = new CRUDExample(); var model = (from product in db.Product where product.Id == id select product).FirstOrDefault(); return View(model); }
public ActionResult Delete(int productOptionId, int productId) { // Set the Product Node's Title SetNodeTitle(GetProductName(productId), 3); var db = new CRUDExample(); var model = (from productOption in db.ProductOption where productOption.Id == productOptionId select productOption).FirstOrDefault(); return View(model); }
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node) { var result = new List<DynamicNode>(); using (var db = new CRUDExample()) { var products = db.Product; foreach (var product in products) { var productKey = "Product_" + product.Id.ToString(); // Create the "Details" node for the product var productNode = new DynamicNode(productKey, "Products", product.Name, product.Name, "Product", "Details"); // Set the "id" route value so the match will work. productNode.RouteValues.Add("id", product.Id); // Set our visibility. This will override what we have configured on the DynamicProducts node. We need to // do this to ensure our products are visible in the /sitemap.xml path. productNode.Attributes["visibility"] = "SiteMapPathHelper,XmlSiteMapResult,!*"; // Add the node to the result result.Add(productNode); // Create the "Edit" node for the product var productEditNode = new DynamicNode("ProductEdit_" + product.Id.ToString(), productKey, "Edit", "Edit", "Product", "Edit"); // Set the "id" route value of the edit node productEditNode.RouteValues.Add("id", product.Id); // Add the node to the result result.Add(productEditNode); // Create the "Delete" node for the product var productDeleteNode = new DynamicNode("ProductDelete_" + product.Id.ToString(), productKey, "Delete", "Delete", "Product", "Delete"); // Set the "id" route value of the delete node productDeleteNode.RouteValues.Add("id", product.Id); // Add the node to the result result.Add(productDeleteNode); } } return result; }
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) { 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; } } var db = new CRUDExample(); var model = (from product in db.Product where product.Id == id select product).FirstOrDefault(); return View(model); }
public ActionResult Delete(int productOptionId, int productId, ProductOption productOption) { try { var db = new CRUDExample(); var model = (from po in db.ProductOption where po.Id == productOptionId select po).FirstOrDefault(); if (model != null) { db.ProductOption.Remove(model); db.SaveChanges(); } return RedirectToAction("Details", "Product", new { productId = productId }); } catch { // Set the Product Node's Title SetNodeTitle(GetProductName(productId), 3); 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 Create(int productId, ProductOption productOption) { try { var db = new CRUDExample(); var model = new ProductOption(); if (model != null) { model.ProductId = productId; model.Name = productOption.Name; db.ProductOption.Add(model); db.SaveChanges(); } return RedirectToAction("Details", "Product", new { productId = productId }); } catch { // Set the Product Node's Title SetNodeTitle(GetProductName(productId), 2); return View(); } }
// // GET: /Product/ public ActionResult Index() { var db = new CRUDExample(); var model = (from product in db.Product select product).ToList(); return View(model); }
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(); } }
// // GET: /Product/Edit/5 public ActionResult Edit(int id) { 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; } } var db = new CRUDExample(); var model = (from product in db.Product where product.Id == id select product).FirstOrDefault(); // Now that we have set the id, the match works for current node var node = SiteMaps.Current.CurrentNode; if (node != null) { // Set a custom attribute - we can set this to any object node.Attributes["CustomKey"] = "SomeCustomValue"; // Set the title and description of the Details node based on database data var parent = node.ParentNode; if (parent != null) { parent.Title = model.Name; parent.Description = model.Name; } } return View(model); }
public ActionResult Details(int id) { ISiteMapNode node; node = SiteMaps.Current.FindSiteMapNodeFromKey("Product_Details"); if (node != null) { node.RouteValues.Add("id", id); } var db = new CRUDExample(); var model = (from product in db.Product where product.Id == id select product).FirstOrDefault(); return View(model); }
private string GetProductName(int productId) { using (var db = new CRUDExample()) { return (from p in db.Product where p.Id == productId select p.Name).FirstOrDefault(); } }