/* DoesPasswordMatch() * Verifies credentials for an account. * * Returns: true if verified, false if password doesn't match or account does * not exist */ public static bool DoesPasswordMatch(string user, string pass) { string cacheName = GetCacheName(user); if (Cache.Exists(cacheName)) { DBAct.UserRecords userData = (DBAct.UserRecords)Cache.Get(cacheName); return(userData.Pass == pass); } return(false); }
/* GetBalance() * Determines net balance of the user's account. * * Modifies: amount with the value of the user's balance * Returns: true if retrieved, false if not retrieved */ public static bool GetBalance(string user, string pass, ref decimal amount) { DBAct.UserRecords userData = null; if (!AuthUserAndFetchData(user, pass, ref userData)) { return(false); } amount = userData.GetBalance(); return(true); }
/* TransactionHistory() * Determines the transaction history of the user. * * Modifies: history to store the account's transaction history. Newest items * will begin at the start of the index. * Returns: true if retrived, false if not retrieved */ public static bool TransactionHistory(string user, string pass, ref string[] history) { DBAct.UserRecords userData = null; if (!AuthUserAndFetchData(user, pass, ref userData)) { return(false); } history = new string[userData.Records.Count]; for (int i = 0; i < userData.Records.Count; i++) { history[i] = Convert.ToString(userData.Records.ElementAt(i).Date) + " ... " + String.Format("{0,17:0.00}", userData.Records.ElementAt(i).Amount); } Array.Reverse(history); //give newest items first return(true); }
/* AddTransaction() * Attempts to add a new transaction to the account. Withdrawals are passed as * negative amounts. Will fail if insufficient funds are detected. * * Returns: true if added, false if not added */ public static bool AddTransaction(string user, string pass, decimal amount) { string cacheName = GetCacheName(user); DBAct.UserRecords userData = null; if (!AuthUserAndFetchData(user, pass, ref userData)) { return(false); } if (userData.GetBalance() + amount < 0) { return(false); } DateTime date = DateTime.Now; Transaction newTransaction = CreateNewTransaction(date, amount); userData.AddTransaction(newTransaction); Cache.Update(cacheName, userData); return(true); }