// GET: Armuor/Edit/{id} public ActionResult Edit(int?id) { var service = GetArmourService(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var single = service.GetSingleArmour(id); ArmourEdit armour = new ArmourEdit() { ArmourClass = single.ArmourClass, ArmourType = single.ArmourType, CostInCurrency = single.CostInCurrency, CurrencyEnumIndex = (int)single.CurrencyRequired, MaxDexMod = single.MaxDexMod, MinStrength = single.MinStrength, Name = single.Name, StealthDisadvantage = single.StealthDisadvantage, WeightInPounds = single.WeightInPounds }; if (armour == null) { return(HttpNotFound()); } return(View(armour)); }
// UPDATE public async Task <bool> UpdateArmourAsync(ArmourEdit model) { if (_context.Armours.Count(e => e.Id == model.Id) != 0) { var entity = _context.Armours.Single(armour => armour.Id == model.Id); if (entity != null) { entity.Name = model.Name; entity.WeightInPounds = model.WeightInPounds; entity.CostInCurrency = model.CostInCurrency; entity.CurrencyRequired = (Currency)model.CurrencyEnumIndex; entity.ArmourClass = model.ArmourClass; entity.MaxDexMod = model.MaxDexMod; entity.MinStrength = model.MinStrength; entity.StealthDisadvantage = model.StealthDisadvantage; entity.ArmourType = model.ArmourType; if (await _context.SaveChangesAsync() == 1) { return(true); } return(false); } return(false); } return(false); }
public async Task <ActionResult> Edit(ArmourEdit model) { if (ModelState.IsValid) { var service = GetArmourService(); if (await service.UpdateArmourAsync(model)) { return(RedirectToAction(nameof(Index))); } } return(View(model)); }