//Edit: AttackEdit public ActionResult Edit(int id) { var service = CreateAttackService(); var detail = service.GetAttackById(id); var model = new AttackEdit { AttackId = detail.AttackId, Name = detail.Name, Text = detail.Text, Damage = detail.Damage, EnergyCost = detail.EnergyCost }; return(View(model)); }
public bool UpdateAttack(AttackEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Attacks.Where(a => a.AttackId == model.AttackId) .FirstOrDefault(); if (entity == null) { return(false); } entity.Name = model.Name; entity.Text = model.Text; entity.Damage = model.Damage; entity.EnergyCost = model.EnergyCost; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, AttackEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.AttackId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateAttackService(); if (service.UpdateAttack(model)) { TempData["SaveResult"] = "Your Attack was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Attack could not be updated."); return(View(model)); }