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 }); }
public void Handle(AccountClosed request) { this.AccountState = AccountState.Closed; this.SequenceNumber = request.SequenceNumber; }