コード例 #1
0
        public void Transfer(Guid accountNoTo, Guid accountNoFrom, decimal amount)
        {
            BankAccount bankAccountTo   = _bankAccountRepository.FindBy(accountNoTo);
            BankAccount bankAccountFrom = _bankAccountRepository.FindBy(accountNoFrom);

            BankAccountHasEnoughFundsToWithdrawSpecification HasEnoughFunds = new BankAccountHasEnoughFundsToWithdrawSpecification(amount);

            if (HasEnoughFunds.IsSatisfiedBy(bankAccountFrom))
            {
                bankAccountTo.Balance += amount;
                Transaction transDeposit = TransactionFactory.CreateDepositTransactionFrom(bankAccountTo, amount, "From Acc " + bankAccountFrom.CustomerRef + " ");
                bankAccountTo.Transactions.Add(transDeposit);

                bankAccountFrom.Balance -= amount;
                Transaction transWithdraw = TransactionFactory.CreateWithdrawTransactionFrom(bankAccountFrom, amount, "Transfer To Acc " + bankAccountTo.CustomerRef + " ");
                bankAccountFrom.Transactions.Add(transWithdraw);

                _bankAccountRepository.Save(bankAccountTo);
                _bankAccountRepository.Save(bankAccountFrom);
            }
            else
            {
                throw new InsufficientFundsException();
            }
        }
コード例 #2
0
        public void Withdraw(Guid accountNo, decimal amount, string reference)
        {
            BankAccount bankAccount = _bankAccountRepository.FindBy(accountNo);

            BankAccountHasEnoughFundsToWithdrawSpecification HasEnoughFunds = new BankAccountHasEnoughFundsToWithdrawSpecification(amount);

            if (HasEnoughFunds.IsSatisfiedBy(bankAccount))
            {
                bankAccount.Balance -= amount;
                Transaction transWithdraw = TransactionFactory.CreateWithdrawTransactionFrom(bankAccount, amount, reference);
                bankAccount.Transactions.Add(transWithdraw);

                _bankAccountRepository.Save(bankAccount);
            }
        }