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);
 }
 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);
 }
 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);
 }
 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");
 }
 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");
 }
 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");
 }
 private decimal Balance(BankAccount bankAccount)
 {
     return _transactions[bankAccount.AccountNumber].Sum(account => account.Amount);
 }
 public void Transfer(BankAccount creditorAccount, BankAccount debtorAccount, decimal amount, string description)
 {
     Withdraw(debtorAccount, amount, description);
     Deposit(creditorAccount, amount, description);
 }