/// <summary> /// Method to get the current balance of a customer based on the accountType /// </summary> /// <param name="trans"></param> /// <returns>Current balance</returns> public double GetBalance(Transactions trans) { BankDataContext bankDataContext = new BankDataContext(); TransactionTable transTable = new TransactionTable(); Customer_Accounts_Table custAcctTable = new Customer_Accounts_Table(); //var checkRecord = bankDataContext.TransactionTables.Where(c => (c.Account_ID == trans.GetAccountID() && c.Customer_ID == trans.GetCustomerID())).Any(); var balance = bankDataContext.Customer_Accounts_Tables.FirstOrDefault(b => (b.Account_ID == trans.GetAccountID() && b.Customer_ID == trans.GetCustomerID())); if (balance == null) { return(0); } else { var checkBalance = bankDataContext.Customer_Accounts_Tables.Where(b => (b.Account_ID == trans.GetAccountID() && b.Customer_ID == trans.GetCustomerID())).Any(); if (!checkBalance) { return(0); } else { return(Convert.ToDouble(balance.Balance)); } } }
/// <summary> /// Method to bridge the Withdraw Transaction and getting the current balance from the db. Uses the customer_accounts_table. /// </summary> /// <param name="trans"></param> /// <returns></returns> public double WithdrawAmount(Transactions trans) { BankDataContext bankDataContext = new BankDataContext(); TransactionTable transTable = new TransactionTable(); Customer_Accounts_Table custAcctTable = new Customer_Accounts_Table(); if (bankDataContext.Customer_Accounts_Tables.Count(a => (a.Account_ID == trans.GetAccountID() && a.Customer_ID == trans.GetCustomerID())) < 1) { custAcctTable.Account_ID = trans.GetAccountID(); custAcctTable.Customer_ID = trans.GetCustomerID(); custAcctTable.Balance = Convert.ToDecimal(trans.GetAmount()); bankDataContext.Customer_Accounts_Tables.InsertOnSubmit(custAcctTable); bankDataContext.SubmitChanges(); return(Convert.ToDouble(custAcctTable.Balance)); } else { var amtQuery = bankDataContext.TransactionTables.Where(t => (t.Account_ID == trans.GetAccountID() && t.Customer_ID == trans.GetCustomerID() && t.Transaction_Type == trans.GetTransactionType().ToString())).ToArray().Last().Amount; Customer_Accounts_Table myCust = bankDataContext.Customer_Accounts_Tables.SingleOrDefault(p => (p.Customer_ID == trans.GetCustomerID() && p.Account_ID == trans.GetAccountID())); myCust.Balance = myCust.Balance - amtQuery; Console.WriteLine(myCust.Balance); bankDataContext.SubmitChanges(); return(Convert.ToDouble(myCust.Balance)); } }
public void AddTransaction(Transactions trans) { BankDataContext bankDataContext = new BankDataContext(); TransactionTable transTable = new TransactionTable(); transTable.Transaction_Type = trans.GetTransactionType().ToString(); transTable.Account_ID = trans.GetAccountID(); transTable.Customer_ID = trans.GetCustomerID(); transTable.Transaction_Date = trans.GetDate().ToString(); transTable.Amount = Convert.ToDecimal(trans.GetAmount()); bankDataContext.TransactionTables.InsertOnSubmit(transTable); bankDataContext.SubmitChanges(); }
/// <summary> /// Method to get all the transactions of a customer from the db /// </summary> /// <param name="custID"></param> /// <returns>List of transactions for a customer</returns> public List <Transactions> GetAllTransactions(int custID) { BankDataContext bankDataContext = new BankDataContext(); TransactionTable transTable = new TransactionTable(); var getAllTransQuery = bankDataContext.TransactionTables.Where(t => t.Customer_ID == custID); List <Transactions> getAllTrans = new List <Transactions>(); foreach (var i in getAllTransQuery) { var getAcctType = bankDataContext.AccountTables.SingleOrDefault(a => a.Account_ID == i.Account_ID).Account_Type; TransactionType getTransactionType = (TransactionType)Enum.Parse(typeof(TransactionType), i.Transaction_Type); AccountType getAccountType = (AccountType)Enum.Parse(typeof(AccountType), getAcctType); DateTime getDate = DateTime.ParseExact(i.Transaction_Date, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); Transactions getAllTransObj = new Transactions(getTransactionType, getAccountType, getDate, Convert.ToDouble(i.Amount)); getAllTrans.Add(getAllTransObj); } return(getAllTrans); }
private void detach_TransactionTables(TransactionTable entity) { this.SendPropertyChanging(); entity.CustomerTable = null; }
partial void DeleteTransactionTable(TransactionTable instance);
partial void UpdateTransactionTable(TransactionTable instance);
partial void InsertTransactionTable(TransactionTable instance);
private void attach_TransactionTables(TransactionTable entity) { this.SendPropertyChanging(); entity.AccountTable = this; }