public void Delete(IObjectIdentifier <ulong> id) { var command = new AddressDeleteCommand(_dataSource, id.Value); if (!command.Execute()) { throw new ResourceNotFoundException(typeof(AddressEntity), id); } }
public async Task <ICommandHandlerAggregateAnswer> Delete(Guid personId, Guid addressId) { var command = new AddressDeleteCommand { PersonId = personId, AddressId = addressId }; return(await dispatcher.Send <AddressDeleteCommand, Person>(command)); }
public Person Take(AddressDeleteCommand command) { var address = Addresses.First(e => e.Id == command.AddressId); this.Addresses.Remove(address); base.AddEvent(new PersonAddressDeletedDomainEvent { AggregateRootId = Id, CommandJson = JsonConvert.SerializeObject(command), UserId = command.UserId }); return(this); }
public async Task <ICommandHandlerAggregateAnswer> HandleAsync(AddressDeleteCommand command) { var answer = new CommandHandlerAggregateAnswer(); var person = await personRepository.Query(command.PersonId); if (person.IsNotNull()) { answer.ValidationResult = this.deleteAddressValidationHandler.Validate(command); if (command.IsValid) { answer.AggregateRoot = await personRepository.Update(person.Take(command)); } } return(answer); }