Ejemplo n.º 1
0
        public async Task <IActionResult> PutAccountPassive(int passiveID, AccountPassiveDTO accountPassiveDTO)
        {
            var accountID = await GetAccountID();

            var accountPassive = await _context.AccountPassives.FindAsync(accountID, passiveID);

            accountPassive.Owned  = accountPassiveDTO.Owned;
            accountPassive.Wanted = accountPassiveDTO.Wanted;

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <AccountPassiveDTO> > PostAccountPassive(AccountPassiveDTO accountPassiveDTO)
        {
            var accountID = await GetAccountID();

            var accountPassive = _mapper.Map <AccountPassive>(accountPassiveDTO);

            accountPassive.AccountId = accountID;

            _context.AccountPassives.Add(accountPassive);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException) when(AccountPassiveExists(accountID, accountPassive.PassiveId))
            {
                return(Conflict());
            }

            return(CreatedAtAction(
                       nameof(GetAccountPassive),
                       new { accountID = accountPassive.AccountId, passiveID = accountPassive.PassiveId },
                       _mapper.Map <AccountPassiveDTO>(accountPassive)
                       ));
        }