public ActionResult Edit(int id) { var service = CreateRoadblockService(); var detail = service.GetRoadblockById(id); var model = new RoadblockEdit { RoadblockId = detail.RoadblockId, RoadblockName = detail.RoadblockName, IsComplete = detail.IsComplete, Plan = detail.Plan }; return(View(model)); }
public bool UpdateRoadblock(RoadblockEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Roadblocks .Single(e => e.RoadblockId == model.RoadblockId && e.OwnerId == _ownerId); entity.RoadblockName = model.RoadblockName; entity.IsComplete = model.IsComplete; entity.Plan = model.Plan; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, RoadblockEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.RoadblockId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateRoadblockService(); if (service.UpdateRoadblock(model)) { TempData["SaveResult"] = "Your roadblock was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your roadblock could not be updated."); return(View(model)); }