public static CommandProcess Start(string email) { var state = AccountState.FromStorage(AccountStore.AccountStates.SingleOrDefault(x => x.Email == email)); if (state == null) { throw new Exception("Not found"); } var account = Account.Create(state); return(new CommandProcess(state, account)); }
public void Handle(BecomeCustomerCommand command) { var state = AccountState.FromStorage(AccountStore.AccountStates.SingleOrDefault(x => x.Email == command.Email)) ?? new AccountState(); var agg = Account.Create(state); agg.BecomeCustomer(command.Email, command.Username); foreach (var change in agg.Changes()) { EventStore.Add(change); } AccountStore.AccountStates.Add(state.ToStorage()); }
public void Handle(PromoteCreditCardAsPrimaryCommand command) { var state = AccountState.FromStorage(AccountStore.AccountStates.SingleOrDefault(x => x.Email == command.Email)); if (state == null) { throw new Exception("Not found"); } var agg = Account.Create(state); agg.PromoteCreditCard(command.CreditCard); foreach (var change in agg.Changes()) { EventStore.Add(change); } AccountStore.Update(state.ToStorage()); }
private CommandProcess(AccountState state, Account account) { _state = state; _account = account; }