internal static T SelectById <T>(string Id) { string type = typeof(T).Name; LogEntry l = new LogEntry("SELECT " + type + " by ID: " + Id, DateTime.Now); try { T[] returnObj = SQL.GetInstance().Select <T>("Id = \"" + Id + "\";"); if (returnObj.Length > 0) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(returnObj[0]); } else { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(default(T)); } } catch (System.Exception) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); throw; } }
internal static Person GetPersonByName(string nameString) { LogEntry l = new LogEntry("Getting " + nameString + " user by name", DateTime.Now); string[] splitName = nameString.Split(' '); Person[] p = SQL.GetInstance().Select <Person>($"FirstName = \"{splitName[0]}\" AND LastName = \"{splitName[1]}\";"); if (p.Length > 0) { if (p[0].FirstName == splitName[0] && p[0].LastName == splitName[1]) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(p[0]); } else { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(null); } } else { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(null); } }
internal static BankUser[] GetBankUsersByName(string Name) { LogEntry l = new LogEntry("GET Bank Users by Name: " + Name, DateTime.Now); BankUser[] users = SQL.GetInstance().Select <BankUser>($"lower(FirstName || ' ' || LastName) = lower(\"{Name}\");"); l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(users); }
internal static void UpdateById <T>(T updatedModel, string Id) { string type = typeof(T).Name; LogEntry l = new LogEntry("Update " + type + " by ID: " + Id, DateTime.Now); try { SQL.GetInstance().Update <T>(updatedModel, "Id = \"" + Id + "\";"); l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); } catch (System.Exception) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); throw; } }
internal static void DeleteById <T>(string Id) { string type = typeof(T).Name; LogEntry l = new LogEntry("DELETE " + type + " by Id: " + Id, DateTime.Now); try { SQL.GetInstance().Delete <T>("Id = \"" + Id + "\";"); l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); } catch (System.Exception e) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); throw e; } }
internal static T InsertNewObject <T>(T objectToInsert) { string type = typeof(T).Name; LogEntry l = new LogEntry("INSERT new " + type, DateTime.Now); try { T t = SQL.GetInstance().Insert <T>(objectToInsert); l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(t); } catch (System.Exception) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); throw; } }
internal static Transactions[] GetTransactionsForUser(string Id) { LogEntry l = new LogEntry("GET Transactions For User: "******"SenderAccountId = \"{Id}\" or ReceiverAccountId = \"{Id}\";"); for (int i = 0; i < t.Length; i++) { if ((t[i].SenderAccountId != Id) && (t[i].ReceiverAccountId != Id)) { List <Transactions> listOfTransactions = new List <Transactions>(t); listOfTransactions.RemoveAt(i); t = listOfTransactions.ToArray(); } } l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(t); }
internal static LoginDetails Login(string email) { LogEntry l = new LogEntry("Login", DateTime.Now); LoginDetails[] logins = SQL.GetInstance().Select <LoginDetails>($"Email = \"{email}\""); if (logins != null && logins.Length == 1) { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(logins[0]); } else { l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); return(null); } }
private void RenderDashboardForChosenRole(Roles role) { List <string> options = new List <string>(); int response; string header = ""; if (role == Roles.Admin) { header = $"Hello {this.person.FirstName} {this.person.LastName}. Your Branch Location is {(person as BankAdmin).BranchLocation}"; options.Add("Make Transaction"); options.Add("View Transactions"); options.Add("Update Transactions"); options.Add("Delete Transactions"); options.Add("View Logs"); options.Add("Logout"); } else if (role == Roles.User) { header = $"Hello {person.FirstName} {person.LastName}. Your account type is {(person as BankUser).AccountType}"; options.Add("Make Transaction"); options.Add("View Transactions"); options.Add("Logout"); } Menu m = new Menu(options.ToArray()); bool goodResponse = false; do { response = m.RenderMenu(header); switch (response) { case -1: case 6: LogEntry l = new LogEntry("Logout", DateTime.Now); this._router.Navigate(Routes.Splash); l.AddEndTime(DateTime.Now); LoggerController.AddToLog(l.ToString()); LogEntry.SetActor("User", Roles.Unauthenticated); Helpers.FreeAndNil(ref l); goodResponse = true; break; case 1: this._router.Navigate(Routes.MakeTransaction, this.person); goodResponse = true; break; case 2: this._router.Navigate(Routes.ViewTransaction, this.person); goodResponse = true; break; case 3: if (role == Roles.User) { this._router.Navigate(Routes.Splash); goodResponse = true; } else if (role == Roles.Admin) { this._router.Navigate(Routes.UpdateTransaction, this.person); goodResponse = true; } break; case 4: if (role == Roles.User) { Console.WriteLine("Bad choice! Try again..."); Console.ReadKey(); Console.Clear(); goodResponse = false; } else if (role == Roles.Admin) { this._router.Navigate(Routes.DeleteTransaction, this.person); goodResponse = true; } break; case 5: if (role == Roles.User) { Console.WriteLine("Bad choice! Try again..."); Console.ReadKey(); Console.Clear(); goodResponse = false; } else if (role == Roles.Admin) { this._router.Navigate(Routes.ViewLogs, this.person); goodResponse = true; } break; default: Console.WriteLine("Bad choice! Try again..."); Console.ReadKey(); Console.Clear(); goodResponse = false; break; } } while (!goodResponse); }