/// <summary> /// Record the transaction and to the database /// </summary> /// <param name="accountId">the account id</param> /// <param name="transactionTypeId">the id of the transaction type</param> /// <param name="amount">amount associated with the transaction</param> /// <param name="notes">note made with the transaction</param> private static void TransactionRecord(int accountId, int transactionTypeId, double amount, string notes) { BankOfBIT_XWContext db = new BankOfBIT_XWContext(); if (transactionTypeId == (int)TransactionTypeValues.Deposit || transactionTypeId == (int)TransactionTypeValues.TransferRecipient) { Transaction transaction = new Transaction(); transaction.BankAccountId = accountId; transaction.TransactionTypeId = transactionTypeId; transaction.Deposit = amount; transaction.Withdrawal = 0; transaction.DateCreated = DateTime.Today; transaction.Notes = notes; db.Transactions.Add(transaction); } if (transactionTypeId == (int)TransactionTypeValues.Withdrawal || transactionTypeId == (int)TransactionTypeValues.BillPayment || transactionTypeId == (int)TransactionTypeValues.Transfer) { Transaction transaction = new Transaction(); transaction.BankAccountId = accountId; transaction.TransactionTypeId = transactionTypeId; transaction.Withdrawal = amount; transaction.Deposit = 0; transaction.DateCreated = DateTime.Today; transaction.Notes = notes; db.Transactions.Add(transaction); } if (transactionTypeId == (int)TransactionTypeValues.CalculateInterest) { if (amount > 0) { Transaction transaction = new Transaction(); transaction.BankAccountId = accountId; transaction.TransactionTypeId = transactionTypeId; transaction.Deposit = amount; transaction.Withdrawal = 0; transaction.DateCreated = DateTime.Today; transaction.Notes = notes; db.Transactions.Add(transaction); } if (amount < 0) { Transaction transaction = new Transaction(); transaction.BankAccountId = accountId; transaction.TransactionTypeId = transactionTypeId; transaction.Withdrawal = System.Math.Abs(amount); transaction.Deposit = 0; transaction.DateCreated = DateTime.Today; transaction.Notes = notes; db.Transactions.Add(transaction); } } db.SaveChanges(); }