public async Task <IActionResult> PutAccountAdventurer(int adventurerID, AccountAdventurerDTO accountAdventurerDTO) { var accountID = await GetAccountID(); var accountAdventurer = await _context.AccountAdventurers.FindAsync(accountID, adventurerID); accountAdventurer.CurrentLevel = accountAdventurerDTO.CurrentLevel; accountAdventurer.WantedLevel = accountAdventurerDTO.WantedLevel; _context.Entry(accountAdventurer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!AccountAdventurerExists(accountID, adventurerID)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <AccountAdventurerDTO> > PostAccountAdventurer(AccountAdventurerDTO accountAdventurerDTO) { var accountID = await GetAccountID(); var accountAdventurer = _mapper.Map <AccountAdventurer>(accountAdventurerDTO); accountAdventurer.AccountId = accountID; _context.AccountAdventurers.Add(accountAdventurer); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) when(AccountAdventurerExists(accountID, accountAdventurer.AdventurerId)) { return(Conflict()); } return(CreatedAtAction( nameof(GetAccountAdventurer), new { accountID = accountAdventurer.AccountId, adventurerID = accountAdventurer.AdventurerId }, _mapper.Map <AccountAdventurerDTO>(accountAdventurer))); }