/// <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 AddCustomerAccount(int custID, int acctID, double balance) { BankDataContext bankDataContext = new BankDataContext(); Customer_Accounts_Table custAcctTable = new Customer_Accounts_Table(); custAcctTable.Account_ID = acctID; custAcctTable.Customer_ID = custID; custAcctTable.Balance = Convert.ToDecimal(balance); bankDataContext.Customer_Accounts_Tables.InsertOnSubmit(custAcctTable); bankDataContext.SubmitChanges(); }
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 add a new customer into the db /// </summary> /// <param name="customer"></param> /// <returns>New generated customerID</returns> public int AddNewCustomer1(Customers customer) { BankDataContext bankDataContext = new BankDataContext(); CustomerTable custTable = new CustomerTable(); bankDataContext.Connection.Open(); custTable.Customer_Address = customer.GetCustomerAddress(); custTable.Customer_Name = customer.GetCustomerName(); custTable.Customer_Telephone = customer.GetCustomerTelephone(); bankDataContext.CustomerTables.InsertOnSubmit(custTable); bankDataContext.SubmitChanges(); // how linq to sql works in fetching the identity column return(custTable.Customer_ID); }