public async Task <DomainCompany> UpdateByUserAsync(string userId, CompanyUpdateOptions update) { CompanyEntity company = await _companyRepository.FindByUserAsync(userId); if (company == null) { throw new NotFoundException(string.Format("Could not find company by user id '{0}'.", userId)); } if (company.State == (int)ResourceState.Blocked) { throw new ForbiddenException(string.Format("Company {0} is blocked", company.Id)); } if (company.State == (int)ResourceState.Deleted) { throw new NotFoundException(string.Format("Company {0} is deleted", company.Id)); } // Patching company.Name = update.Name; company.NameSort = update.Name == null ? null : update.Name.ToLowerInvariant(); company.Country = update.Country; company.Ein = update.Ein; company.Address = update.Address; company.ZipCode = update.ZipCode; company.Phone = update.Phone; company.Email = update.Email; company = await _companyRepository.UpdateAsync(company); return(_mapper.Map <CompanyEntity, DomainCompany>(company)); }
public async Task <HttpResponseMessage> Put(ClientModel model) { // Change e-mail await _userService.ChangeEmailAsync(UserId, model.Email); // Update user var userUpdate = new UserUpdateOptions { Country = model.Country, UserName = model.ContactPerson }; DomainUser user = await _userService.UpdateAsync(UserId, userUpdate); // Update company var companyUpdate = new CompanyUpdateOptions { Address = model.Address, Country = model.Country, Ein = model.Ein, Name = model.CompanyName, Phone = model.PhoneNumber, ZipCode = model.ZipCode, Email = model.Email }; DomainCompany company = await _companyService.UpdateByUserAsync(UserId, companyUpdate); Client client = _mapper.Map <Tuple <DomainUser, DomainCompany>, Client>(new Tuple <DomainUser, DomainCompany>(user, company)); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, client); return(response); }