public async Task <ICommandHandlerAggregateAnswer> Delete(Guid personId, Guid creditCardId) { var command = new CreditCardDeleteCommand { PersonId = personId, CreditCardId = creditCardId }; return(await dispatcher.Send <CreditCardDeleteCommand, Person>(command)); }
public Person Take(CreditCardDeleteCommand command) { var creditCard = CreditCards.First(e => e.Id == command.CreditCardId); this.CreditCards.Remove(creditCard); base.AddEvent(new PersonCreditCardDeleteDomainEvent { AggregateRootId = Id, CommandJson = JsonConvert.SerializeObject(command), UserId = command.UserId }); return(this); }
public async Task <ICommandHandlerAggregateAnswer> HandleAsync(CreditCardDeleteCommand command) { var answer = new CommandHandlerAggregateAnswer(); var person = await personRepository.Query(command.PersonId); if (person.IsNotNull()) { answer.ValidationResult = this.deleteCreditCardValidationHandler.Validate(command); if (command.IsValid) { answer.AggregateRoot = await personRepository.Update(person.Take(command)); } } return(answer); }