public Task <bool> Handle(UpdatePersonCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var person = new Person(message.Id, message.Name, message.Email, message.Password, message.DtRegister, message.Active); var existingPerson = _personRepository.GetByEmail(person.Email); if (existingPerson != null && existingPerson.Id != person.Id) { //se o obj retornado nao for igual ao 'person' if (!existingPerson.Equals(person)) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "O e-mail desta pessoa já está sendo usado!")); return(Task.FromResult(false)); } } person = new Person(message.Id, message.Name, message.Email, message.Password, existingPerson.DtRegister, message.Active); _personRepository.Update(person); if (Commit()) { //Bus.RaiseEvent(new PersonUpdatedEvent(person.Id, person.Name, person.Email, person.Password, person.DtRegister, person.Active)); } return(Task.FromResult(true)); }
public Task <bool> Handle(UpdatePersonCommand command, CancellationToken cancellationToken) { if (!command.IsValid()) { NotifyValidationErrors(command); return(Task.FromResult(false)); } var person = new Person(command.Id, command.Name, command.Address, command.Age); //Validação person cadastrado var personCadastrado = personReadRepository.GetByIdAsync(person.Id).Result; if (personCadastrado != null) { mediator.RaiseEventAsync(new DomainNotification(command.MessageType, "Essa pessoa já está cadastrado na base de dados!")); return(Task.FromResult(false)); } personWriteRepository.Update(person); if (Commit()) { mediator.RaiseEventAsync(new UpdatePersonEvent(person.Id, person.Name, person.Address, person.Age)); } return(Task.FromResult(true)); }
public void Handle(UpdatePersonCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } var person = new PersonModel(message.FirstName, message.LastName, message.Gender, message.Age); personRepository.Update(person); if (Commit()) { // Bus.RaiseEvent(new CustomerUpdatedEvent(customer.Id, customer.Name, customer.Email, customer.BirthDate)); } }
public Task Handle(UpdatePersonCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.CompletedTask); } var person = new Person(message.PersonId, message.FirstName, message.LastName, message.CPF, message.Email, message.DateOfBirth, message.Phone, message.Address, message.Gender, message.IsActive, new BloodType(message.BloodType, "")); _personRepository.Update(person); if (Commit()) { Bus.RaiseEvent(new PersonUpdatedEvent(person.PersonId, person.FirstName, person.LastName, person.CPF, person.Email, person.DateOfBirth, person.Phone, person.Address, person.Gender, person.IsActive, person.BloodType.BloodTypeId)); } return(Task.CompletedTask); }
public Task <bool> Handle(UpdatePersonCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var person = new Person(message.Id, message.Name); _postRepository.Update(person); if (Commit()) { _bus.RaiseEvent(new PersonUpdatedEvent(person.Id, person.Name)); } return(Task.FromResult(true)); }