public ActionResult Edit(int id) { var service = CreateTechnicianService(); var detail = service.GetTechnicianById(id); var model = new TechnicianEdit { TechnicianID = detail.TechnicianID, TechnicianName = detail.TechnicianName, TechnicianPhoneNumber = detail.TechnicianPhoneNumber, TechnicianEmail = detail.TechnicianEmail }; return(View(model)); }
public bool UpdateTechnician(TechnicianEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Technician .Single(e => e.TechnicianID == model.TechnicianID); entity.TechnicianID = model.TechnicianID; entity.TechnicianName = model.TechnicianName; entity.TechnicianPhoneNumber = model.TechnicianPhoneNumber; entity.TechnicianEmail = model.TechnicianEmail; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, TechnicianEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TechnicianID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateTechnicianService(); if (service.UpdateTechnician(model)) { TempData["SaveResult"] = "Technician has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Technician could not be updated."); return(View(model)); }