internal override void Render() { bool isRightAnswer = false; int chosenIndex = -1; Transactions chosenTransaction = null; Console.WriteLine("Deleting a transaction"); BankUser u = SearchForUsers(); Transactions[] transactions = GetTransactions(u.Id); Console.WriteLine($"Transactions for {u.FirstName} {u.LastName}"); Helpers.FreeAndNil(ref u); TableHelpers.RenderTable(transactions); do { Console.Write("Select the transaction to edit by writing it's number: "); if (int.TryParse(Console.ReadLine(), out chosenIndex)) { if (chosenIndex - 1 < 0 || chosenIndex - 1 >= transactions.Length) { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(transactions.Length + 1); } else { chosenTransaction = transactions[chosenIndex - 1]; isRightAnswer = true; } } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(transactions.Length + 1); } } while (!isRightAnswer); Helpers.FreeAndNil(ref transactions); if (chosenTransaction.ReceiverAccountId != this.user.Id && chosenTransaction.SenderAccountId != this.user.Id) { Helpers.FreeAndNil(ref chosenTransaction); Console.WriteLine("You attempted to delete a transaction that does not belong to you! Quitting the app..."); Environment.Exit(1); } else { AppController.GetInstance().TransactionController.DeleteTransaction(chosenTransaction.Id); Helpers.FreeAndNil(ref chosenTransaction); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); this._router.Navigate(Routes.Dashboard, this.user); } }
private Currency GetCurrency(string currency = "") { bool rightAnswer = false; int selectedCurrency = -1; Currency c = null; if (currency == "") { do { Console.WriteLine("Select currency to send your payment in:"); for (int i = 0; i < currencies.Length; i++) { Console.WriteLine($"{i + 1}) {currencies[i].CurrencyLongName}"); } Console.Write("Select your currency: "); if (int.TryParse(Console.ReadLine(), out selectedCurrency)) { if (selectedCurrency - 1 < 0 || selectedCurrency - 1 > currencies.Length) { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(currencies.Length + 3); } else { c = currencies[selectedCurrency - 1]; rightAnswer = true; } } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(currencies.Length + 3); } } while (!rightAnswer); } else { Currency curr = null; for (int i = 0; i < currencies.Length; i++) { if (currencies[i].CurrencyShortName.ToString().ToLower() == currency.ToLower()) { curr = currencies[i]; break; } } c = curr; } return(c); }
internal override void Render() { bool isRightAnswer = false; int chosenIndex; Transactions chosenTransaction = null; Console.WriteLine("Updating a transaction"); BankUser u = SearchForUsers(); Transactions[] transactions = GetTransactions(u.Id); Console.WriteLine($"Transactions for {u.FirstName} {u.LastName}"); TableHelpers.RenderTable(transactions); do { Console.Write("Select the transaction to edit by writing it's number: "); if (int.TryParse(Console.ReadLine(), out chosenIndex)) { if (chosenIndex - 1 < 0 || chosenIndex - 1 >= transactions.Length) { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(transactions.Length + 1); } else { chosenTransaction = transactions[chosenIndex - 1]; isRightAnswer = true; } } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(transactions.Length + 1); } } while (!isRightAnswer); UpdateChosenTransaction(chosenTransaction); Helpers.FreeAndNil(ref chosenTransaction); Helpers.FreeAndNil(ref transactions); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); this._router.Navigate(Routes.Dashboard, this.user); }
internal int RenderMenu(string header = "") { bool isDone = false; int response = 0; string menuChoice = ""; do { if (header != "") { Console.WriteLine(header); } for (int i = 0; i < options.Length; i++) { Console.WriteLine($"{i + 1}) {options[i]}"); } Console.Write("> "); menuChoice = Console.ReadLine(); if (menuChoice.Trim().ToLower() == ":q") { return(-1); } isDone = int.TryParse(menuChoice, out response); if (response != 0) { if (response > options.Length) { Console.WriteLine("You have chosen a bad menu option. Try again!"); isDone = false; Console.Read(); ConsoleExtensions.ClearLines(1 + options.Length); } } }while (!isDone); return(response); }
private decimal GetAmount(string currency) { decimal amount; bool rightAnswer = false; do { Console.Write($"\nEnter Amount: {currency}"); if (decimal.TryParse(Console.ReadLine(), out amount)) { rightAnswer = true; } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(2); } } while (!rightAnswer); return(amount); }
private BankUser SearchForUsers(string name = "") { bool rightAnswer = false; int chosenUser = -1; BankUser chosenBankUser = null; bool foundPerson = false; string nameInput = ""; BankUser[] users = null; do { if (name != "") { nameInput = name; } else { Console.Write("Enter name: "); nameInput = Console.ReadLine(); } users = BankUser.GetBankUsersByName(nameInput); if (users.Length == 0) { do { Console.Write("No users found! Try Again? (y/n) "); nameInput = Console.ReadLine(); if (nameInput.ToLower() == "y") { ConsoleExtensions.ClearLines(3); rightAnswer = true; } else if (nameInput.ToLower() == "n") { rightAnswer = true; Helpers.FreeAndNil(ref users); _router.Navigate(Routes.Dashboard, this.user); } else { Console.WriteLine("Wrong choice!"); Console.ReadKey(); ConsoleExtensions.ClearLines(3); } } while (!rightAnswer); } else { do { Console.WriteLine("The System Found these users:"); for (int i = 0; i < users.Length; i++) { BankUser user = users[i]; Console.WriteLine($"{i + 1}) {user.FirstName} {user.LastName}, {user.Address1}, {user.Address2}, {user.Address3}"); } Console.Write("\nSelect your user: "******"Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(users.Length + 4); } else { chosenBankUser = users[chosenUser - 1]; rightAnswer = true; foundPerson = true; } } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(users.Length + 4); } } while (!rightAnswer); } } while (!foundPerson); Helpers.FreeAndNil(ref users); Helpers.FreeAndNil(ref user); return(chosenBankUser); }
private void UpdateChosenTransaction(Transactions t) { string input; bool rightAnswer = false; decimal amount; Console.Write($"Sender ({((t.SenderAccount != null) ? t.SenderAccount.FirstName + " " + t.SenderAccount.LastName : "")}): "); input = Console.ReadLine(); if (input != "") { BankUser u = SearchForUsers(input); t.SenderAccount = u; t.SenderAccountId = u.Id; } Console.Write($"Receiver ({((t.SenderAccount != null) ? t.SenderAccount.FirstName + " " + t.SenderAccount.LastName : "")}): "); input = Console.ReadLine(); if (input != "") { BankUser u = SearchForUsers(input); t.ReceiverAccount = u; t.ReceiverAccountId = u.Id; } do { Console.Write($"Currency ({t.SmallCurrencyString}): "); input = Console.ReadLine(); if (input != "") { Currency c = GetCurrency(input); if (c == null) { Console.WriteLine("Bad answer try again!"); Console.ReadKey(); ConsoleExtensions.ClearLines(2); } else { t.SmallCurrencyString = c.CurrencyShortName; t.LargeCurrencyString = c.CurrencyLongName; rightAnswer = true; } } else { rightAnswer = true; } } while (!rightAnswer); rightAnswer = false; do { Console.Write($"Amount ({t.SmallCurrencyString}{t.Amount}): {t.SmallCurrencyString}"); input = Console.ReadLine(); if (input == "") { rightAnswer = true; } else if (decimal.TryParse(input, out amount)) { t.Amount = amount; rightAnswer = true; } else { Console.WriteLine("Bad answer. Try again!"); Console.ReadLine(); ConsoleExtensions.ClearLines(2); } } while (!rightAnswer); AppController.GetInstance().TransactionController.UpdateTransaction(t); Helpers.FreeAndNil(ref t); }
internal override void Render() { Transactions transaction = new Transactions(); BankUser sender = null; BankUser receiver; bool adminUserCheck = false; if (_user.Role == Roles.Admin) { Console.WriteLine("You are about to make a transation as an Admin."); Console.WriteLine("Search for a person to transfer funds from: "); sender = SearchForUsers(); if (sender == null) { return; } else if (sender.GetType() == typeof(BankUser)) { transaction.SenderAccountId = sender.Id; } else { return; } } else { Console.WriteLine("You are about to make a transaction from your account."); transaction.SenderAccountId = _user.Id; } do { Console.WriteLine("Search for a person to transfer funds to:"); receiver = SearchForUsers(); if (receiver == null) { return; } if (receiver.GetType() == typeof(BankUser)) { transaction.ReceiverAccountId = receiver.Id; } else { return; } if (sender.Id == receiver.Id) { Console.WriteLine("You cannot make a transaction to yourself!"); Console.WriteLine("Press any key to try again..."); Console.ReadKey(); ConsoleExtensions.ClearLines(3); } else { adminUserCheck = true; } } while (!adminUserCheck); Helpers.FreeAndNil(ref receiver); Helpers.FreeAndNil(ref sender); Currency c = GetCurrency(); transaction.SmallCurrencyString = c.CurrencyShortName; transaction.LargeCurrencyString = c.CurrencyLongName; transaction.Amount = GetAmount(c.CurrencyShortName); transaction.Timestamp = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds(); Transactions.InsertNewObject(transaction); Console.WriteLine("Your new transaction has been inserted!"); Console.WriteLine("You can view it on the dashboard."); Console.ReadKey(); Helpers.FreeAndNil(ref transaction); _router.Navigate(Routes.Dashboard, this._user); }
internal override void Render() { if (user.Role == Roles.User) { Transactions[] t = AppController.GetInstance().TransactionController.GetTransactionsForUser(this.user.Id); Array.Sort(t, delegate(Transactions x, Transactions y) { return(y.Timestamp.CompareTo(x.Timestamp)); }); Console.WriteLine($"Transactions for {user.FirstName} {user.LastName}"); if (t.Length > 0) { TableHelpers.RenderTable(t); } else { Console.WriteLine("No transactions for this account."); } Helpers.FreeAndNil(ref t); } else if (user.Role == Roles.Admin) { string name = ""; BankUser chosenUser = null; BankUser[] users = null; bool isDone = false; bool rightAnswer = false; int chosenIndex = -1; do { Console.Write("Enter the name of a user to search for: "); name = Console.ReadLine(); users = AppController.GetInstance().UserController.GetBankUsersByName(name); if (users.Length < 1) { do { Console.Write("No users found! Try Again? (y/n) "); name = Console.ReadLine(); if (name.ToLower() == "y") { ConsoleExtensions.ClearLines(2); rightAnswer = true; } else if (name.ToLower() == "n") { rightAnswer = true; _router.Navigate(Routes.Dashboard, this.user); return; } else { Console.WriteLine("Wrong choice!"); Console.ReadKey(); ConsoleExtensions.ClearLines(2); } } while (!rightAnswer); } else { do { Console.WriteLine("The System Found these users:"); for (int i = 0; i < users.Length; i++) { BankUser user = users[i]; Console.WriteLine($"{i + 1}) {user.FirstName} {user.LastName}, {user.Address1}, {user.Address2}, {user.Address3}"); } Console.Write("\nSelect your user: "******"Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(users.Length + 4); } else { chosenUser = users[chosenIndex - 1]; isDone = true; rightAnswer = true; } } else { Console.WriteLine("Bad answer! Try again! "); Console.ReadKey(); ConsoleExtensions.ClearLines(users.Length + 3); } } while (!rightAnswer); } } while (!isDone); Transactions[] t = AppController.GetInstance().TransactionController.GetTransactionsForUser(chosenUser.Id); Array.Sort(t, delegate(Transactions x, Transactions y) { return(y.Timestamp.CompareTo(x.Timestamp)); }); Console.WriteLine($"Transactions for {chosenUser.FirstName} {chosenUser.LastName}"); if (t.Length > 0) { TableHelpers.RenderTable(t); } else { Console.WriteLine("No transactions for this account."); } Helpers.FreeAndNil(ref t); Helpers.FreeAndNil(ref chosenUser); Helpers.FreeAndNil(ref users); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); this._router.Navigate(Routes.Dashboard, this.user); }
private bool SetupLogin(Person p) { string email; SecureString password = new SecureString(); Console.Clear(); Console.WriteLine("Now setup your credentials: \n"); Console.Write("Email: "); email = Console.ReadLine(); Console.Write("Password: "******"\b"); Console.Write(' '); Console.Write("\b"); } Console.WriteLine(); Console.WriteLine("Password is too weak! Try again! (Hint: The requirement is:"); Console.WriteLine("- Minimum 8 Characters"); Console.WriteLine("- One Capital Letter"); Console.WriteLine("- One Lowecase Letter"); Console.WriteLine("- One Number"); Console.WriteLine("- One Symbol"); Console.WriteLine(); Console.ReadKey(); ConsoleExtensions.ClearLines(8); Console.Write("Password: "******"\b"); Console.Write(' '); Console.Write("\b"); } } else { password.AppendChar(key.KeyChar); Console.Write('*'); } } Console.WriteLine(); bool result = AppController.GetInstance().LoginController.Register(email, password, p); Helpers.FreeAndNil(ref p); Helpers.FreeAndNil(ref email); password.Dispose(); return(result); }