Пример #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());
        }
Пример #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));
        }
Пример #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));
        }