public override async Task <ActionResult> Post(Client newClient) { var person = await _peopleRepository.GetPersonByEmail(newClient.Person.Email); if (person == null) { await _peopleController.AddPerson(newClient.Person); var getPerson = await _peopleRepository.GetPersonByEmail(newClient.Person.Email); getPerson.UserName = newClient.Person.Email; await _userManager.UpdateAsync(getPerson); } else { newClient.Person.Id = person.Id; foreach (var address in newClient.Person.Addresses) { address.PersonId = person.Id; } await _peopleController.UpdatePerson(newClient.Person); } var client = new Client { PersonId = _peopleRepository.GetPersonId(newClient.Person.Email) }; return(await _repository.Add(client)); }