public ActionResult DeleteConfirmed(int id) { SetForeignKeysToNull(id); OPSystem oPSystem = db.OperatingSystems.Find(id); db.OperatingSystems.Remove(oPSystem); db.SaveChanges(); TempData["OPSystemStatusMessage"] = "Operating system has been deleted successfully!"; return(RedirectToAction("Index")); }
// GET: OPSystems/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OPSystem oPSystem = db.OperatingSystems.Find(id); if (oPSystem == null) { return(HttpNotFound()); } return(View(oPSystem)); }
public ActionResult Edit([Bind(Include = "OPSystemId,OpSystemName,Description")] OPSystem oPSystem) { if (ModelState.IsValid) { if (CanUpdateOPSystem(oPSystem)) { db.Entry(oPSystem).State = EntityState.Modified; db.SaveChanges(); TempData["OPSystemStatusMessage"] = "Operating system has been updated successfully!"; return(RedirectToAction("Index")); } DisplayOPSystemExistsMessage(oPSystem); } return(View(oPSystem)); }
public ActionResult Create([Bind(Include = "OPSystemId,OpSystemName,Description")] OPSystem oPSystem) { if (ModelState.IsValid) { if (CanAddOPSystem(oPSystem.OpSystemName)) { db.OperatingSystems.Add(oPSystem); db.SaveChanges(); TempData["OPSystemStatusMessage"] = "Operating system has been added successfully!"; return(RedirectToAction("Index")); } DisplayOPSystemExistsMessage(oPSystem); } return(View(oPSystem)); }
private void DisplayOPSystemExistsMessage(OPSystem o) { ModelState.AddModelError("OpSystemName", $"Model {o.OpSystemName} already exists please choose another name."); }
private bool CanUpdateOPSystem(OPSystem opS) { var query = db.OperatingSystems.Where(o => o.OPSystemId != opS.OPSystemId).Any(o => o.OpSystemName == opS.OpSystemName); return(!query); }