public async Task <ICommandHandlerAggregateAnswer> Delete(Guid personId, Guid emailAddressId) { var command = new EmailAddressDeleteCommand { PersonId = personId, MailAddressId = emailAddressId }; return(await dispatcher.Send <EmailAddressDeleteCommand, Person>(command)); }
public Person Take(EmailAddressDeleteCommand command) { var mail = EmailAddresses.First(e => e.Id == command.MailAddressId); this.EmailAddresses.Remove(mail); base.AddEvent(new PersonEmailAddressDeletedDomainEvent { AggregateRootId = Id, CommandJson = JsonConvert.SerializeObject(command), UserId = command.UserId }); return(this); }
public async Task <ICommandHandlerAggregateAnswer> HandleAsync(EmailAddressDeleteCommand command) { var answer = new CommandHandlerAggregateAnswer(); var person = await personRepository.Query(command.PersonId); if (person.IsNotNull()) { answer.ValidationResult = this.deleteMailValidationHandler.Validate(command); if (command.IsValid) { answer.AggregateRoot = await personRepository.Update(person.Take(command)); } } return(answer); }