public async Task <IActionResult> AddAddress(AddressAddDto newAddress) { ServiceResponse <List <AddressGetDto> > response = await _addressService.AddAddress(newAddress); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public static Address ToEntity(this AddressAddDto dto) { return(new Address() { Id = Guid.NewGuid(), Street = dto.Street, Number = dto.Number, PostalCode = dto.PostalCode, City = dto.City, Country = dto.Country }); }
public async Task <ServiceResponse <List <AddressGetDto> > > AddAddress(AddressAddDto newAddress) { ServiceResponse <List <AddressGetDto> > serviceResponse = new ServiceResponse <List <AddressGetDto> >(); Address Address = _mapper.Map <Address>(newAddress); try { await _context.Addresses.AddAsync(Address); await _context.SaveChangesAsync(); serviceResponse.Data = (_context.Addresses.Select(u => _mapper.Map <AddressGetDto>(u))).ToList(); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }