/// <summary> /// createTransactionRecord - Creates a new transaction record and inserts it into the transactions table /// </summary> /// <param name="accountId">BankAccountId of the bank account being updated</param> /// <param name="amount">The amount being deposited or withdrawn from the bank account</param> /// <param name="notes">Transaction notes</param> /// <param name="transactionType">The type of transaction indicated</param> private void createTransactionRecord(int accountId, double amount, string notes, Utility.TransactionTypeValues transactionType) { //Create a new instance of Transaction Transaction transaction = new Transaction(); if (transactionType == Utility.TransactionTypeValues.TransferRecipient || transactionType == Utility.TransactionTypeValues.Deposit) { transaction.Deposit = amount; transaction.Withdrawal = 0; } else { transaction.Deposit = 0; transaction.Withdrawal = amount; } //Update the fields of the newly created transaction inside the Transaction table transaction.SetNextTransactionNumber(); transaction.BankAccountId = accountId; transaction.TransactionTypeId = (int)transactionType; transaction.DateCreated = DateTime.Now; transaction.Notes = notes; db.Transactions.Add(transaction); //Save changes made to the database db.SaveChanges(); }
/// <summary> /// updateAccountBalance - Updates the BankAccount balance and returns the new balance /// </summary> /// <param name="accountId">BankAccountId of the bank account being updated</param> /// <param name="amount">The amount being withdrawn from the bank account for a bill payment</param> /// <param name="notes">Transaction notes</param> /// <param name="transactionType">The type of transaction</param> /// <returns>The updated balance of the corresponding bank account</returns> private double?updateAccountBalance(int accountId, double amount, Utility.TransactionTypeValues transactionType) { double?balance = 0; try { //Returns a record from the BankAccount table BankAccount account = (from results in db.BankAccounts where results.BankAccountId == accountId select results).SingleOrDefault(); if (transactionType == Utility.TransactionTypeValues.Deposit) { account.Balance += amount; } else { //If the account type is anything other than depost, subtract that amount from the balance field account.Balance -= amount; } //Ensures the Bank Account's state corresponds to its new balance account.ChangeState(); //Save changes made to the database db.SaveChanges(); balance = account.Balance; } catch (Exception) { balance = null; } return(balance); }