Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TransactionManager : ITransactionManager
- {
- BankOfBIT_RIContext db = new BankOfBIT_RIContext();
- public void DoWork()
- {
- }
- public double? Deposit(int accountId, double amount, string notes)
- {
- double? total;
- try
- {
- total = Utility(accountId, amount, notes, (int)TransactionTypeValues.Deposit);
- }
- catch
- {
- total = null;
- }
- return total;
- }
- private double? Utility(int accountId, double amount, string notes, int type)
- {
- double? total;
- try
- {
- //create bank account object using linq
- BankAccount bankQuery = (from bank in db.BankAccounts
- where bank.BankAccountId == accountId
- select bank).SingleOrDefault();
- bankQuery.Balance += amount;
- bankQuery.ChangeState();
- db.SaveChanges();
- CreateTransaction(accountId, amount, notes, type);
- total = bankQuery.Balance;
- }
- catch
- {
- total = null;
- }
- return total;
- }
- private void CreateTransaction(int accountId, double amount, string notes, int type)
- {
- //make an if based on type just to modify the deposits and withdrawals
- Transaction trans;
- if (type == (int)TransactionTypeValues.Deposit || type == (int)TransactionTypeValues.TransferRecipient)
- {
- trans = new Transaction
- {
- BankAccountId = accountId,
- TransactionTypeId = type,
- Deposit = amount,
- Withdrawal = 0,
- DateCreated = DateTime.Now,
- Notes = notes
- };
- trans.SetNextTransactionNumber();
- }
- else
- {
- trans = new Transaction
- {
- BankAccountId = accountId,
- TransactionTypeId = type,
- Deposit = amount,
- Withdrawal = 0,
- DateCreated = DateTime.Now,
- Notes = notes
- };
- }
- db.Transactions.Add(trans);
- db.SaveChanges();
- }
- public double? Withdrawal(int accountId, double amount, string notes)
- {
- double? total;
- try
- {
- total = Utility(accountId, -amount, notes, (int)TransactionTypeValues.Withdrawal);
- }
- catch
- {
- total = null;
- }
- return total;
- }
- public double? BillPayment(int accountId, double amount, string notes)
- {
- return Utility(accountId, amount, notes, (int)TransactionTypeValues.BillPayment);
- }
- public double? Transfer(int fromAccountId, int toAccountId, double amount, string notes)
- {
- double? total;
- try
- {
- total = Utility(fromAccountId, -amount, notes, (int)TransactionTypeValues.Transfer);
- Utility(toAccountId, amount, notes, (int)TransactionTypeValues.Transfer);
- }
- catch
- {
- total = null;
- }
- return total;
- }
- public double? CalculateInterest(int accountId, string notes)
- {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement