public bool UpdatePlatoon(PlatoonEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .PlatoonDbSet .Single(e => e.PlatoonId == model.Id); entity.Name = model.Name; entity.Familiar = model.Familiar; entity.Assigned = model.Assigned; entity.Squads = model.Squads; entity.Teams = model.Teams; return(ctx.SaveChanges() == 1); } }
//GET: Platoon/Edit/id public ActionResult Edit(int id) { var svc = CreatePlatoonService(); var detail = svc.GetPlatoonById(id); var model = new PlatoonEdit { Id = detail.Id, Name = detail.Name, Familiar = detail.Familiar, Assigned = detail.Assigned, Squads = detail.Squads, Teams = detail.Teams }; return(View(model)); }
public ActionResult Edit(int id, PlatoonEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.Id != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var svc = CreatePlatoonService(); if (svc.UpdatePlatoon(model)) { TempData["SaveResult"] = "Record updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Unable to update record."); return(View()); }