Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            var entity = await AccountDto.ToEntity(id, _context);

            if (entity == null)
            {
                return(NotFound());
            }
            _context.Accounts.Remove(entity);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put(AccountDto dto)
        {
            var entity = await AccountDto.ToEntity(dto, _context);

            if (entity == null)
            {
                return(NotFound());
            }

            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { }, dto));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <AccountDto> > Post(AccountDto dto)
        {
            var entity = await AccountDto.ToEntity(dto, _context);

            if (entity == null)
            {
                return(NotFound());
            }

            await _context.Accounts.AddAsync(entity);

            await _context.SaveChangesAsync();

            var contractDto = AccountDto.FromEntity(entity);

            return(CreatedAtAction("Get", new { }, contractDto));
        }