// GET: Weapon/Edit/{id} public ActionResult Edit(int?id) { var service = GetArmourService(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var single = service.GetSingleWeapon(id); WeaponEdit weapon = new WeaponEdit() { Name = single.Name, WeightInPounds = single.WeightInPounds, CostInCurrency = single.CostInCurrency, CurrencyEnumIndex = (int)single.CurrencyRequired, IsMartialWeapon = single.IsMartialWeapon, IsMeleeWeapon = single.IsMeleeWeapon, DamageDieAmount = single.DamageDieAmount, DamageDieSize = single.DamageDieSize, DamageType = single.DamageType }; if (weapon == null) { return(HttpNotFound()); } return(View(weapon)); }
// UPDATE public async Task <bool> UpdateWeaponAsync(WeaponEdit model) { if (_context.Weapons.Count(e => e.Id == model.Id) != 0) { var entity = _context.Weapons.Single(Weapon => Weapon.Id == model.Id); if (entity != null) { entity.Name = model.Name; entity.WeightInPounds = model.WeightInPounds; entity.CostInCurrency = model.CostInCurrency; entity.CurrencyRequired = (Currency)model.CurrencyEnumIndex; entity.IsMartialWeapon = model.IsMartialWeapon; entity.IsMeleeWeapon = model.IsMeleeWeapon; entity.DamageDieAmount = model.DamageDieAmount; entity.DamageDieSize = model.DamageDieSize; entity.DamageType = model.DamageType; if (await _context.SaveChangesAsync() == 1) { return(true); } return(false); } return(false); } return(false); }
public async Task <ActionResult> Edit(WeaponEdit model) { if (ModelState.IsValid) { var service = GetArmourService(); if (await service.UpdateWeaponAsync(model)) { return(RedirectToAction(nameof(Index))); } } return(View(model)); }
public ActionResult EditWeaponItem(WeaponEdit item) => Edit(item);