// GET: Edit // Position/Edit/{id} public ActionResult Edit(int id) { var service = CreatePositionService(); var detail = service.GetPositionById(id); var model = new PositionEdit { PositionId = detail.PositionId, PositionName = detail.PositionName, Notes = detail.Notes }; return(View(model)); }
public bool UpdatePosition(PositionEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Positions .Single(e => e.OwnerId == _userId && e.PositionId == model.PositionId); entity.PositionName = model.PositionName; entity.Notes = model.Notes; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, PositionEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PositionId != id) { ModelState.AddModelError("", "The Id's do not match."); return(View(model)); } var service = CreatePositionService(); if (service.UpdatePosition(model)) { TempData["SaveResult"] = $"{model.PositionName} has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "This position has not been updated successfully."); return(View()); }