public bool UpdateInvestigator(InvestigatorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Investigators .Single(e => e.InvestigatorID == model.InvestigatorID); entity.Name = model.Name; entity.Email = model.Email; entity.Address = model.Email; entity.PhoneNumber = model.PhoneNumber; return(ctx.SaveChanges() == 1); } }
public ActionResult InvestigatorEdit(int id) { var svc = new InvestigatorService(); var detail = svc.GetInvestigatorByID(id); var model = new InvestigatorEdit { InvestigatorID = detail.InvestigatorID, Name = detail.Name, Email = detail.Email, Address = detail.Address, PhoneNumber = detail.PhoneNumber, }; return(View(model)); }
public ActionResult InvestigatorEdit(int id, InvestigatorEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.InvestigatorID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var svc = new InvestigatorService(); if (svc.UpdateInvestigator(model)) { TempData["SaveResult"] = "The Investigator was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The Investigator could not be updated"); return(View(model)); }