public ActionResult Edit(int id) { var service = CreateStateAttorneyService(); var detail = service.GetStateAttorneysById(id); var model = new StateAttorneyEdit { FirstName = detail.FirstName, LastName = detail.LastName }; return(View(model)); }
public bool UpdateStateAttorney(int id, StateAttorneyEdit model) { using (var sat = new ApplicationDbContext()) { var entity = sat .StateAttorneys .Single(e => e.StateAttorneyID == id); entity.FirstName = model.FirstName; entity.LastName = model.LastName; return(sat.SaveChanges() == 1); } }
public ActionResult Edit(int id, StateAttorneyEdit model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateStateAttorneyService(); if (service.UpdateStateAttorney(id, model)) { TempData["SaveResult"] = "State Attorney Updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "State Attorney not Updated"); return(View(model)); }