public ActionResult Edit(int id) { var service = CreateEraService(); var detail = service.GetEraById(id); var model = new EraEdit { EraId = detail.EraId, EraName = detail.EraName, }; return(View(model)); }
//EDIT public bool UpdateEra(EraEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Eras .Single(e => e.EraId == model.EraId); entity.EraName = model.EraName; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, EraEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.EraId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateEraService(); if (service.UpdateEra(model)) { TempData["SaveResult"] = "Your Era was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Era could not be updated."); return(View(model)); }