Esempio n. 1
0
        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());
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
 private CommandProcess(AccountState state, Account account)
 {
     _state   = state;
     _account = account;
 }