public BankAccount UnFreeze(EventDateTime requestedOn)
        {
            if (State.IsFrozen == false)
            {
                return(this);
            }

            return(ApplyEvent(new AccountUnfrozen(Id, GetNextEventId(), requestedOn)));
        }
        public BankAccount Deposit(Money amount, EventDateTime requestedOn)
        {
            if (State.IsFrozen)
            {
                throw new AccountIsFrozenException();
            }

            return(ApplyEvent(new FundsDeposited(Id, GetNextEventId(), requestedOn, amount)));
        }
        public BankAccount Withdraw(Money amount, EventDateTime requestedOn)
        {
            if (State.IsFrozen)
            {
                throw new AccountIsFrozenException();
            }

            var sufficientFunds = State.CurrentBalance >= amount;

            if (!sufficientFunds)
            {
                throw new InsufficientFundsException();
            }

            return(ApplyEvent(new FundsWithdrawn(Id, GetNextEventId(), requestedOn, amount)));
        }
 public static BankAccount OpenNewAccount(AccountId id, EventDateTime eventOn)
 =>
 new BankAccount(
     id,
     ImmutableList.Create <BankAccountEvent>(new AccountCreated(id, EventId.NewId(), eventOn)),
     InitialState);
Exemple #5
0
 public FundsWithdrawn(AccountId appliesTo, EventId id, EventDateTime occuredOn, Money amount)
     : base(appliesTo, id, occuredOn)
 {
     AmountWithdrawn = amount;
 }