Exemple #1
0
        public void AddDeposit(BankTransaction transaction)
        {
            if (transaction.Amount < 0)
            {
                throw new ApplicationException("The amount value is invalid. Any deposit must be greater than ZERO!");
            }

            Transactions.Add(transaction);
            CalculateBalance();
        }
Exemple #2
0
        public void AddWithdraw(BankTransaction transaction)
        {
            if (transaction.Amount >= 0)
            {
                throw new ApplicationException("The amount value is invalid. Any withdraw must be less than zero!");
            }


            var totalBalance = TotalBalance - (transaction.Amount * -1);

            if (totalBalance < 0)
            {
                throw new ApplicationException($"The amount value is invalid. The amount must be less or equal to balance. {transaction.Amount} > {TotalBalance}");
            }

            Transactions.Add(transaction);
            CalculateBalance();
        }