public async Task <Enterprise> SaveAsync(EnterpriseDTOFull enterpriseDTO) { if (enterpriseDTO != null) { Enterprise enterprise = await _enterpriseRepository.FindByIdAsync(enterpriseDTO.Id); if (enterprise == null) { enterprise = new Enterprise(); } Mapper.Map <EnterpriseDTOFull, Enterprise>(enterpriseDTO, enterprise); enterprise.EnterpriseAddress = enterpriseDTO.Addresses.Select(x => new EnterpriseAddress() { Address = new Address { Id = x.Id, Name = x.Name, City = x.City, Country = x.Country, PostalCode = x.PostalCode, Street = x.Street, StreetNumber = x.StreetNumber }, EnterpriseId = enterprise.Id, HeadOffice = x.HeadOffice }).ToList(); await _enterpriseRepository.UpsertAsync(enterprise); return(enterprise); } else { throw new ArgumentNullException(nameof(enterpriseDTO)); } }
public async Task <IActionResult> PutOrPost([FromBody] EnterpriseDTOFull enterpriseDTO) { var item = await _enterpriseService.SaveAsync(enterpriseDTO); return(CreatedAtAction(nameof(Get), new { id = item.Id }, item)); }