Repository navigation
Expand file tree
/
Copy pathMenu.cs
More file actions
190 lines (173 loc) · 7.36 KB
/
Copy pathMenu.cs
File metadata and controls
190 lines (173 loc) · 7.36 KB
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
using System.Security.Principal;
using Microsoft.VisualBasic;
using Serilog;
namespace ConsoleApp2
{
class Menu
{
static void PrintHelpMenu()
{
Console.WriteLine("========== Help Menu ==========");
Console.WriteLine("Please select a menu option:");
Console.WriteLine("logexercise (le) - Log a single exercise (cardio or lift).");
Console.WriteLine("logsession (ls) - Log an entire session with multiple exercises.");
Console.WriteLine();
Console.WriteLine("listall (la) - List all workouts in the DB.");
Console.WriteLine();
Console.WriteLine("\nquit (q) - Quit the app");
}
public static string GetStringInput(string InputType) // WITH INPUT VALIDATION YAY
{
while(true) // keep going til valid input
try
{
Console.Write(">>>");
string Input = Console.ReadLine() ?? "".ToLower();
Log.Verbose("User entered string {Input}", Input);
if(InputType == "time")
{
string[] parts = Input.Split(':'); // make sure right format
if (parts.Length != 2)
throw new FormatException();
else
return Input;
}
else
{
return Input;
}
}
catch(FormatException)
{
if(InputType == "time")
{
Log.Warning("Invalid input. Please enter in MM:SS format.");
}
else
Log.Warning("Invalid input, please try again.");
}
}
public static int GetIntInput() // WITH INPUT VALIDATION YAY
{
while(true) // keep going til valid input
try
{
Console.Write(">>>");
int Input = Int32.Parse(Console.ReadLine() ?? "");
Log.Verbose("User entered int {Input}", Input);
return Input;
}
catch(FormatException)
{
Log.Warning("Invalid input, please try again.");
}
}
public static DateTime GetDateInput() // WITH INPUT VALIDATION YAY
{
while(true) // keep going til valid input (which returns)
try
{
Console.Write(">>>");
DateTime input = DateTime.Parse(Console.ReadLine() ?? "");
Log.Verbose("User entered date {input}", input);
return input;
}
catch(FormatException)
{
Log.Warning("Invalid input, please enter date in format MM/dd/yyyy.");
}
}
public static void BeginLoop()
{
Log.Verbose("Begin menu loop");
string MenuSelection = "";
while (MenuSelection != "q")
{
PrintHelpMenu();
MenuSelection = GetStringInput("menu");
Log.Verbose("User entered menu command '{MenuSelection}'", MenuSelection);
switch (MenuSelection)
{
case "le":
case "logexercise":
Console.WriteLine("What is the date for this exercise? Please enter in format MM/dd/yyyy:");
DateTime Date = GetDateInput();
LogExercise(NewSession(Date));
break;
case "ls":
case "logsession":
LogSession(); // returns WorkoutDate if success
break;
case "la":
case "listall":
ListAllWorkouts();
//Console.WriteLine("Would you like to modify a workout?");
break;
case "q":
case "quit":
return; // exit Program
default: // invalid input
Log.Warning("Entered: '{MenuSelection}'. Please select a valid command.", MenuSelection);
break; // return to help menu
}
}
Log.Verbose("End menu loop");
}
static void LogExercise(int SessionId)
{
string ExerciseType, ExerciseName;
Console.WriteLine("What type of workout is this: Cardio (c) or Weightlifting (w)?:");
ExerciseType = GetStringInput("");
if(ExerciseType == "cardio" || ExerciseType == "c")
{
ExerciseType = "cardio"; //if user entered "c", we want to store "cardio" in DB
Console.WriteLine("Enter name of Cardio: ");
ExerciseName = GetStringInput("");
Console.WriteLine("Enter duration in MM:SS format:");
string[] DurationInput = GetStringInput("time").Split(":");
int DurationSeconds = (Int32.Parse(DurationInput[0]) * 60) + Int32.Parse(DurationInput[1]);
WorkoutManagement.InsertWorkout(ExerciseType, ExerciseName, 0, 0, DurationSeconds, SessionId);
}
else if(ExerciseType == "weightlifting" || ExerciseType == "w")
{
int Weight, Reps;
ExerciseType = "weightlifting"; //if user entered "w", we want to store "weightlifting" in DB
Console.WriteLine("Enter name of Lift:");
ExerciseName = GetStringInput("");
Console.WriteLine("Please enter the amount of weight in pounds:");
Weight = GetIntInput();
Console.WriteLine("Please enter number of reps:");
Reps = GetIntInput();
WorkoutManagement.InsertWorkout(ExerciseType, ExerciseName, Weight, Reps, 0, SessionId);
}
}
static int NewSession(DateTime DateInput)
{
WorkoutManagement.InsertSession(DateInput);
int SessionId = WorkoutManagement.GetNewestSessionId(); //assuming only one user
Log.Information("New Session ID Created with ID: {SessionId}", SessionId);
return SessionId;
}
static void LogSession()
{
Console.Clear();
Console.WriteLine("========== Log Session ==========");
Console.WriteLine("Please enter the date in format MM/dd/yyyy for this session: ");
DateTime DateInput = GetDateInput();
Console.WriteLine("How many exercises are in this session? (INTEGER): ");
int NumExercises = GetIntInput();
int SessionId = NewSession(DateInput);
for(int i = 1; i <= NumExercises; i++)
{
Console.WriteLine($"\n====Exercise #{i}====");
LogExercise(SessionId);
}
}
static public void ListAllWorkouts()
{
string ReturnString = WorkoutManagement.GetAllWorkouts();
Console.WriteLine(ReturnString);
Console.ReadLine();
}
}
}