-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrompts.cs
213 lines (195 loc) · 6.67 KB
/
Prompts.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Purpose: Contains the prompts for the user to interact with the banking app
using Newtonsoft.Json.Linq;
namespace BankingApp
{
public class Prompts
{
static BankAccount account = null;
/// <summary>
/// Prompts the user to retrieve the accounts
/// </summary>
public static void retrieveAccountsPrompt()
{
JObject retrieveAccounts = JObject.Parse(Bank.retrieveAccounts());
Console.WriteLine(retrieveAccounts["message"]);
}
/// <summary>
/// Main menu for the banking app
/// </summary>
public static void menu()
{
Console.WriteLine();
Console.WriteLine("Main Menu");
Console.WriteLine("Select an Option");
Console.WriteLine("1. Sign In");
Console.WriteLine("2. Create Account");
Console.WriteLine("3. Exit");
Console.Write("Enter Option: ");
string response = Console.ReadLine().Trim();
if(MainMenuOptions.TryGetValue(response, out Action action))
{
action();
if (!response.Equals("3")) menu();
}
else
{
Console.WriteLine("Incorrect Response. Try Again");
menu();
}
}
/// <summary>
/// Sub menu for the banking app
/// </summary>
public static void subMenu()
{
Console.WriteLine();
Console.WriteLine("Sub Menu");
Console.WriteLine("Select an Option");
Console.WriteLine("1. Deposit");
Console.WriteLine("2. Withdraw");
Console.WriteLine("3. View Account");
Console.WriteLine("4. Sign Out");
Console.Write("Enter Option: ");
string response = Console.ReadLine().Trim();
if (SubMenuOptions.TryGetValue(response, out Action action))
{
action();
if (!response.Equals("4")) subMenu();
}
else
{
Console.WriteLine("Incorrect Response. Try Again");
subMenu();
}
}
/// <summary>
/// Prompts the user to sign in
/// </summary>
public static void SignInPrompt()
{
string username = Validation.validateUsername();
string PIN = Validation.validatePIN();
account = Bank.SignIn(username, PIN);
if (account == null)
{
Console.WriteLine("Invalid Username or password");
}
else
{
Console.WriteLine("Signed in Successfully");
Console.WriteLine($"Welcome {account.getUserName()}");
subMenu();
}
}
/// <summary>
/// Prompts the user to deposit
/// </summary>
public static void DepositPrompt()
{
double amount = Validation.validateAmount();
JObject response = JObject.Parse(account.Deposit(amount));
if (!(bool)response["status"])
{
Console.WriteLine(response["message"]);
}
else
{
Console.WriteLine(response["message"]);
Console.WriteLine($"New Balance: {response["balance"]}");
}
}
/// <summary>
/// Prompts the user to withdraw
/// </summary>
public static void WithdrawPrompt()
{
double amount = Validation.validateAmount();
JObject response = JObject.Parse(account.Withdraw(amount));
if (!(bool)response["status"])
{
Console.WriteLine(response["message"]);
}
else
{
Console.WriteLine(response["message"]);
Console.WriteLine($"New Balance: {response["balance"]}");
};
}
/// <summary>
/// Prompts the user to view the account
/// </summary>
public static void ViewAccountPrompt()
{
Console.WriteLine($"{account.ToString()}");
}
/// <summary>
/// Prompts the user to create an account
/// </summary>
public static void CreateAccountPrompt()
{
string username = Validation.validateUsername();
string email = Validation.validateEmail();
string phone = Validation.validatePhone();
string name = Validation.validateName();
string PIN = Validation.validatePIN();
JObject response = JObject.Parse(Bank.CreateAccount(username, name, PIN, email, phone));
if((bool)response["status"])
{
Console.WriteLine(response["message"]);
Console.WriteLine($"Account Details: {response["accountDetails"].ToString() }");
}
else
{
Console.WriteLine(response["message"]);
}
}
/// <summary>
/// Prompts the user to exit
/// </summary>
public static void exitPrompt()
{
Console.WriteLine("Exiting...");
}
/// <summary>
/// Prompts the user to sign out
/// </summary>
public static void signOutPrompt()
{
Console.WriteLine("Signing Out...");
account = null;
}
/// <summary>
/// Prompts the user to save the accounts
/// </summary>
public static void saveAccountsPrompt()
{
JObject message = JObject.Parse(Bank.saveAccounts());
Console.WriteLine(message["message"]);
}
/// <summary>
/// Dictionary containing the main menu options
/// </summary>
/// <typeparam name="string"></typeparam>
/// <typeparam name="Action"></typeparam>
/// <returns></returns>
public static Dictionary<string, Action> MainMenuOptions = new Dictionary<string, Action>()
{
{"1", SignInPrompt},
{"2", CreateAccountPrompt},
{"3", exitPrompt}
};
/// <summary>
/// Dictionary containing the sub menu options
/// </summary>
/// <typeparam name="string"></typeparam>
/// <typeparam name="Action"></typeparam>
/// <returns></returns>
public static Dictionary<string, Action> SubMenuOptions = new Dictionary<string, Action>()
{
{"1", DepositPrompt},
{"2", WithdrawPrompt},
{"3", ViewAccountPrompt},
{"4", signOutPrompt}
};
}
}