public async Task <IActionResult> PutAccountWeapon(int weaponID, AccountWeaponDTO accountWeaponDTO) { var accountID = await GetAccountID(); var accountWeapon = await _context.AccountWeapons.FindAsync(accountID, weaponID); accountWeapon.Copies = accountWeaponDTO.Copies; accountWeapon.CopiesWanted = accountWeaponDTO.CopiesWanted; accountWeapon.WeaponLevel = accountWeaponDTO.WeaponLevel; accountWeapon.WeaponLevelWanted = accountWeaponDTO.WeaponLevelWanted; accountWeapon.Unbind = accountWeaponDTO.Unbind; accountWeapon.UnbindWanted = accountWeaponDTO.UnbindWanted; accountWeapon.Refine = accountWeaponDTO.Refine; accountWeapon.RefineWanted = accountWeaponDTO.RefineWanted; accountWeapon.Slot = accountWeaponDTO.Slot; accountWeapon.SlotWanted = accountWeaponDTO.SlotWanted; accountWeapon.Dominion = accountWeaponDTO.Dominion; accountWeapon.DominionWanted = accountWeaponDTO.DominionWanted; accountWeapon.Bonus = accountWeaponDTO.Bonus; accountWeapon.BonusWanted = accountWeaponDTO.BonusWanted; _context.Entry(accountWeapon).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!AccountWeaponExists(accountID, weaponID)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <AccountWeapon> > PostAccountWeapon(AccountWeaponDTO accountWeaponDTO) { var accountID = await GetAccountID(); var accountWeapon = _mapper.Map <AccountWeapon>(accountWeaponDTO); accountWeapon.AccountId = accountID; _context.AccountWeapons.Add(accountWeapon); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) when(AccountWeaponExists(accountWeapon.AccountId, accountWeapon.WeaponId)) { return(Conflict()); } return(CreatedAtAction( nameof(GetAccountWeapon), new { accountID = accountWeapon.AccountId, weaponID = accountWeapon.WeaponId }, _mapper.Map <AccountWeaponDTO>(accountWeapon))); }