示例#1
0
        public async Task <IActionResult> PutAccountDragon(int dragonID, AccountDragonDTO accountDragonDTO)
        {
            var accountID = await GetAccountID();

            var accountDragon = await _context.AccountDragons.FindAsync(accountID, dragonID);

            accountDragon.Unbind       = accountDragonDTO.Unbind;
            accountDragon.UnbindWanted = accountDragonDTO.UnbindWanted;

            _context.Entry(accountDragon).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!AccountDragonExists(accountID, dragonID))
            {
                return(NotFound());
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <AccountDragonDTO> > PostAccountDragon(AccountDragonDTO accountDragonDTO)
        {
            var accountID = await GetAccountID();

            var accountDragon = _mapper.Map <AccountDragon>(accountDragonDTO);

            accountDragon.AccountId = accountID;

            _context.AccountDragons.Add(accountDragon);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException) when(AccountDragonExists(accountID, accountDragon.DragonId))
            {
                return(Conflict());
            }

            return(CreatedAtAction(
                       nameof(GetAccountDragon),
                       new { accountID = accountDragon.AccountId, dragonID = accountDragon.DragonId },
                       _mapper.Map <AccountDragonDTO>(accountDragon)
                       ));
        }