Пример #1
0
        public IEnumerable <AggregateEvent> CloseAccount(CloseAccountCommand command)
        {
            if (this.AccountState == AccountState.Closed)
            {
                throw new InvalidOperationException($"Account {AccountNumber} is already closed.");
            }

            if (this.CurrentBalance > 0)
            {
                throw new InvalidOperationException($"Account {AccountNumber} still has money on it. Please withdraw before closing.");
            }

            var aggregateEvent = new AccountClosed(command.AccountNumber, ++SequenceNumber);

            Handle(aggregateEvent);

            return(new AggregateEvent[]
            {
                aggregateEvent
            });
        }
Пример #2
0
 public void Handle(AccountClosed request)
 {
     this.AccountState   = AccountState.Closed;
     this.SequenceNumber = request.SequenceNumber;
 }