-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdminMenu.cs
67 lines (57 loc) · 2.75 KB
/
AdminMenu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using FoxBank.Models;
namespace FoxBank
{
internal class AdminMenu
{
internal static void LoggedInAdminMenu()
{
Menu mainAdminMenu = new Menu(new string[] { "Create User", "View as User", "Open new account", "Sign out" });
mainAdminMenu.PrintMenu();
bool showAdminMenu = true;
while (showAdminMenu)
{
int index = mainAdminMenu.UseMenu();
switch (index)
{
case 0:
CreateUser();
break;
case 1:
Menu.LoggedInMenu();
break;
case 2:
Menu.OpenAccount();
break;
default: break;
}
}
}
internal static void CreateUser()
{
AsciiArt.PrintHeader();
string firstName = Helper.InputStringValidator("What's the users first name? ");
string lastName = Helper.InputStringValidator("What's the users last name? ");
string pinCode = Helper.InputStringValidator("What's the users pin code? ");
string email = Helper.InputStringValidator("What's the users email adress? ");
// Load role from db, select role names, and turn it into an array.
List<BankRoleModel> roles = PostgresDataAccess.LoadBankRoleModel();
string[] roleArray = roles.Select(role => Helper.FirstCharToUpper(role.name)).ToArray();
int roleIndex = Helper.MenuIndexer(roleArray, false, "Select Which Permission Role the User Should Have: ");
int roleId = roles[roleIndex].id;
// Load branch from db, select branch names, and turn it into an array.
List<BankBranchModel> branches = PostgresDataAccess.LoadBankBranchModel();
string[] branchArray = branches.Select(branch => Helper.FirstCharToUpper(branch.name)).ToArray();
int branchIndex = Helper.MenuIndexer(branchArray, false, "Select Which Branch the User is From: ");
int branchId = branches[branchIndex].id;
PostgresDataAccess.CreateUserModel(firstName, lastName, pinCode, roleId, branchId, email);
Helper.Delay();
AsciiArt.PrintHeader();
Console.WriteLine($"\n-------------------------------------------------\n\n" +
$"Created User: {firstName} {lastName} - With {Helper.FirstCharToUpper(roles[roleIndex].name)} Permissions" +
$" - From: {branches[branchIndex].name}.\n\n" +
$"-------------------------------------------------\n");
Helper.EnterToContinue();
LoggedInAdminMenu();
}
}
}