Example #1
0
        public void Apply(DomainEvents.PostTransaction e)
        {
            var acct = Accounts.Find(a => a.AccountNumber.Equals(e.AccountNumber));

            decimal newBalance = acct.Balance + e.Amount;

            if (acct != null)
            {
                acct.Balance = newBalance;
            }
        }
Example #2
0
        public bool CanApply(DomainEvents.PostTransaction @event)
        {
            var acct = Accounts.Find(a => a.AccountNumber.Equals(@event.AccountNumber));

            if (acct == null)
            {
                throw new DomainValidationException($"Invalid Account {@event.AccountNumber}.");
            }

            decimal newBalance = acct.Balance + @event.Amount;

            if (acct.Balance >= 0 && newBalance < 0)
            {
                throw new DomainValidationException("Insufficient funds.");
            }

            return(true);
        }