protected override void Dispose(bool disposing) { _db = new ProductsGH(); if (disposing) { _db.Dispose(); } base.Dispose(disposing); }
public ActionResult DeleteConfirmed(int id) { _db = new ProductsGH(); Products product = _db.Products.Find(id); _db.Products.Remove(product); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,Name,Description, URL,Value")] Products product) { _db = new ProductsGH(); if (ModelState.IsValid) { _db.Entry(product).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
// GET: Products/Edit/5 public ActionResult Edit(int?id) { _db = new ProductsGH(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Products product = _db.Products.Find(id); if (product == null) { return(HttpNotFound()); } return(View(product)); }
public ActionResult Create([Bind(Include = "ID,Name,Description,URL,Value")] Products product) { _db = new ProductsGH(); if (ModelState.IsValid) { if (_db.Products.FirstOrDefault() == null) { product.ID = 0; //First Element in BD } else { int maxId = _db.Products.Max(prod => prod.ID); product.ID = maxId + 1; } _db.Products.Add(product); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
// GET: Products public ActionResult Index() { _db = new ProductsGH(); return(View(_db.Products.ToList())); }