public bool UpdateAffirmation(AffirmationEdit model) { var existingEntry = _db.Affirmations .Single(x => x.AffirmationId == model.AffirmationId); existingEntry.AffirmationText = model.AffirmationText; return(_db.SaveChanges() == 1); }
public ActionResult Edit(int id) { var service = new AffirmationService(); var detail = service.GetAffirmationById(id); var model = new AffirmationEdit { AffirmationId = detail.AffirmationId, AffirmationText = detail.AffirmationText }; return(View(model)); }
public ActionResult Edit(int id, AffirmationEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.AffirmationId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new AffirmationService(); if (service.UpdateAffirmation(model)) { TempData["SaveResult"] = "Your entry was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Sorry, your entry could not be updated."); return(View(model)); }