//Edit: Weakness Edit public ActionResult Edit(int id) { var service = CreateWeaknessService(); var detail = service.GetWeaknessById(id); var model = new WeaknessEdit { WeaknessId = detail.WeaknessId, Type = detail.Type, Value = detail.Value }; return(View(model)); }
public bool UpdateWeakness(WeaknessEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Weaknesses.Where(a => a.WeaknessId == model.WeaknessId) .FirstOrDefault(); if (entity == null) { return(false); } entity.Type = model.Type; entity.Value = model.Value; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, WeaknessEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.WeaknessId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateWeaknessService(); if (service.UpdateWeakness(model)) { TempData["SaveResult"] = "Your Weakness was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Weakness could not be updated."); return(View(model)); }