public ActionResult Edit(int id) { var service = CreateSalesRepService(); var detail = service.GetSalesRepById(id); var model = new SalesRepEdit { RepId = detail.RepId, RepName = detail.RepName, Territory = detail.Territory }; return(View(model)); }
public bool UpdateSalesRep(SalesRepEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .SalesReps .Single(e => e.RepId == model.RepId); entity.RepName = model.RepName; entity.Territory = model.Territory; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, SalesRepEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.RepId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateSalesRepService(); if (service.UpdateSalesRep(model)) { TempData["SaveResult"] = "The SalesRep was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The SalesRep could not be updated."); return(View()); }