コード例 #1
0
ファイル: BankAccount.cs プロジェクト: vitordm/MyBank
        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();
        }
コード例 #2
0
ファイル: BankAccount.cs プロジェクト: vitordm/MyBank
        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();
        }