private void Execute(ChangeCustomer command) { var customer = _aggregateEventStore.GetAggregate <Customer>(command.Id); customer.Change(command.Name); _aggregateEventStore.Save(customer); }
//out service methods should accept commands as arguments public void Update(ChangeCustomer command) { var customer = context.Find <Customer>(command.id); //since we have a custom command processing which recognizes the specific exception //we can turn it into a user friendly error if (customer == null) { throw new CustomException($"Invalid customer id: {customer.id}"); } //and leave a trail of events for the relevant changes var mobileChanged = CheckMobileChanged(customer, command.mobile); var passportChanged = CheckPassportChanged(customer, command.documents); ApplyChanges(customer, command); //since current context works directly on the DB, let's optimize it by avoiding work if we don't need to if (command.GetValidationErrors().Count == 0) { context.Update(customer); if (mobileChanged != null) { context.Submit(mobileChanged); } if (passportChanged != null) { context.Submit(passportChanged); } } }
public void ShowChangeCustomerWindow(Customer customer) { ChangeCustomer cc = new ChangeCustomer(); cc.CustomerToChange = customer; cc.Show(); }
public void Handle(ChangeCustomer command) { service.Update(command); }