コード例 #1
0
 public void Deposit(BankAccount account, decimal amount, string description)
 {
     if (!_transactions.ContainsKey(account.AccountNumber))
     {
         _transactions.Add(account.AccountNumber, new List<Transaction>());
     }
     var transaction = new Transaction { AccountNumber = account.AccountNumber, Amount = amount, Description = description };
     _transactions[account.AccountNumber].Add(transaction);
 }
コード例 #2
0
 public void Create(string customerName, AccountType accountType)
 {
     var account = new BankAccount
                       {
                           AccountNumber = _bankAccounts.Count.ToString("00000000"),
                           AccountType = accountType,
                           CustomerName = customerName,
                           OverdraftLimit = 0
                       };
     _bankAccounts.Add(account);
 }
コード例 #3
0
 public void Withdraw(BankAccount account, decimal amount, string description)
 {
     if (!_transactions.ContainsKey(account.AccountNumber))
     {
         _transactions.Add(account.AccountNumber, new List<Transaction>());
     }
     if (Balance(account) < amount)
     {
         throw new InsufficientFundsException(account.AccountNumber, amount);
     }
     var transaction = new Transaction { AccountNumber = account.AccountNumber, Amount = -amount, Description = description };
     _transactions[account.AccountNumber].Add(transaction);
 }
コード例 #4
0
 public void Deposit(BankAccount account, decimal amount, string description)
 {
     Console.WriteLine("Deposit of {0} to account {1}", amount, account.AccountNumber);
     try
     {
         _transactionService.Deposit(account, amount, description);
     }
     catch (System.Exception e)
     {
         Console.WriteLine("Exception occurred: {0}", e.Message);
         throw new FaultException("An error occurred despositing money to an account");
     }
     Console.WriteLine("Successfully deposited");
 }
コード例 #5
0
 public void Transfer(BankAccount creditorAccount, BankAccount debtorAccount, decimal amount, string description)
 {
     Console.WriteLine("Traansfer of {0} from account {1} to account {2}", amount, debtorAccount.AccountNumber, creditorAccount);
     try
     {
         _transactionService.Transfer(creditorAccount, debtorAccount, amount, description);
     }
     catch (InsufficientFundsException e)
     {
         Console.WriteLine("Exception occurred: {0}", e.Message);
         throw e.ToFaultException();
     }
     catch (System.Exception e)
     {
         Console.WriteLine("Exception occurred: {0}", e.Message);
         throw new FaultException("An error occurred transferring money between accounts");
     }
     Console.WriteLine("Successfully withdrawn");
 }
コード例 #6
0
 public void Withdraw(BankAccount account, decimal amount, string description)
 {
     Console.WriteLine("Withdrawal of {0} from account {1}", amount, account.AccountNumber);
     try
     {
         _transactionService.Withdraw(account, amount, description);
     }
     catch(InsufficientFundsException e)
     {
         Console.WriteLine("Exception occurred: {0}", e.Message);
         throw e.ToFaultException();
     }
     catch (System.Exception e)
     {
         Console.WriteLine("Exception occurred: {0}", e.Message);
         throw new FaultException("An error occurred withdrawing from an account");
     }
     Console.WriteLine("Successfully withdrawn");
 }
コード例 #7
0
 private decimal Balance(BankAccount bankAccount)
 {
     return _transactions[bankAccount.AccountNumber].Sum(account => account.Amount);
 }
コード例 #8
0
 public void Transfer(BankAccount creditorAccount, BankAccount debtorAccount, decimal amount, string description)
 {
     Withdraw(debtorAccount, amount, description);
     Deposit(creditorAccount, amount, description);
 }