public ActionResult Edit(int id, Product product) { try { using (DbModels dbModel = new DbModels()) { dbModel.Entry(product).State = EntityState.Modified; dbModel.SaveChanges(); } // TODO: Add update logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Product product) { try { using (DbModels dbModel = new DbModels()) { dbModel.Products.Add(product); dbModel.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here using (DbModels dbModel = new DbModels()) { Product product = dbModel.Products.Where(x => x.Id == id).FirstOrDefault(); dbModel.Products.Remove(product); dbModel.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }