public ActionResult EditPost(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Wine_Type wine_TypeToUpdate = db.Wine_Types.Find(id); if (TryUpdateModel(wine_TypeToUpdate, "", new string[] { "wtName" })) { try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } return(View(wine_TypeToUpdate)); }
// GET: Wine_Type/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Wine_Type wine_Type = db.Wine_Types.Find(id); if (wine_Type == null) { return(HttpNotFound()); } return(View(wine_Type)); }
public ActionResult Create([Bind(Include = "ID,wtName")] Wine_Type wine_Type) { try { if (ModelState.IsValid) { db.Wine_Types.Add(wine_Type); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(wine_Type)); }
public ActionResult DeleteConfirmed(int id) { Wine_Type wine_Type = db.Wine_Types.Find(id); try { db.Wine_Types.Remove(wine_Type); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException dex) { if (dex.InnerException.InnerException.Message.Contains("FK_")) { ModelState.AddModelError("", "You cannot delete a Wine Type that has wines in the system."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } return(View(wine_Type)); }