public ActionResult Edit(int id) { var service = CreateCenterService(); var detail = service.GetCenterById(id); var model = new CenterEdit { CenterId = detail.CenterId, Name = detail.Name, City = detail.City, State = detail.State }; return(View(model)); }
public bool UpdateCenter(CenterEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Centers .Single(e => e.CenterId == model.CenterId); entity.Name = model.Name; entity.City = model.City; entity.State = model.State; entity.Country = model.Country; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, CenterEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CenterId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateCenterService(); if (service.UpdateCenter(model)) { TempData["SaveResult"] = "Your note was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your note could not be updated."); return(View(model)); }