public Task<HttpResponseMessage> Put([FromBody]dynamic body) { var listAddress = _serviceAddress.AddToPerson(body.person.address); var listPhone = _servicePhone.AddToPerson(body.person.phone); var commandPerson = new UpdatePersonCommand( id: Guid.Parse((string)body.person.id), name: (string)body.person.name, birthDate: (DateTime)body.person.birthDate, genre: (EGenre)body.person.genre, address: listAddress, phone: listPhone, phototgraph: (string)body.person.photograph ); var person = _servicePerson.Update(commandPerson); _serviceAddress.CheckAddressRemoved(listAddress, person.Id); _servicePhone.CheckPhoneRemoved(listPhone, person.Id); var commandUser = new UpdateUserCommand( id: (string)body.id, password: (string)body.password, userName: (string)body.email, idPerson: person.Id ); var user = _service.Update(commandUser); return CreateResponse(HttpStatusCode.Created, user); }
public Person Update(UpdatePersonCommand command) { Person person = _repository.GetOneIncludeDetails(command.Id); if (command.BirthDate != null) person.ChangeBirthDate(command.BirthDate); if (!string.IsNullOrEmpty(command.Name)) person.ChangeName(command.Name); if (!string.IsNullOrEmpty(command.Photograph)) person.ChangePhotograph(command.Photograph); foreach (var address in command.Address) { person.AddAddress(address); } foreach (var phone in command.Phone) { person.AddPhone(phone); } _repository.Update(person); if (Commit()) return person; return null; }