Пример #1
0
        public async Task <IActionResult> PutAddress(long id, InsertAddressVM addressDto)
        {
            if (id != addressDto.Id)
            {
                return(BadRequest());
            }

            var address = _mapper.Map <Address>(addressDto);

            _context.Entry(address).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <Address> > PostAddress(InsertAddressVM addressDto)
        {
            var address = _mapper.Map <Address>(addressDto);

            _context.Addresses.Add(address);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAddress", new { id = address.Id }, address));
        }