-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cs
141 lines (112 loc) · 3.62 KB
/
Menu.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
using System.Collections.Generic;
using System.Text;
namespace Mammoth_Cave_Quick_Trippin_;
public class Menu
{
private DistrictRepository _districtRepository = new DistrictRepository();
private EmployeeRepository _employeeRepository = new EmployeeRepository();
private enum MenuOption
{
ShowDistricts = 1,
GenerateDistrictReport,
AddDistrict,
RemoveDistrict,
UpdateDistrictSales,
ShowEmployees,
AddEmployee,
RemoveEmployee,
EditEmployee,
AddStore,
Exit
}
private bool _running;
public void Show()
{
_running = true;
while (_running)
{
Console.Clear();
string menuText = GetMenuAsText();
Console.Write(menuText);
string input = Console.ReadLine();
MenuOption chooseOption = (MenuOption)int.Parse(input);
switch (chooseOption)
{
case MenuOption.ShowDistricts:
ShowDistricts();
break;
case MenuOption.GenerateDistrictReport:
_districtRepository.GetDistrictReport();
break;
case MenuOption.AddDistrict:
_districtRepository.SaveNewDistrict();
break;
case MenuOption.RemoveDistrict:
_districtRepository.RemoveDistrict();
break;
case MenuOption.UpdateDistrictSales:
_districtRepository.UpdateDistrictSales();
break;
case MenuOption.ShowEmployees:
ShowEmployees();
break;
case MenuOption.AddEmployee:
_employeeRepository.SaveNewEmployee();
break;
case MenuOption.RemoveEmployee:
_employeeRepository.RemoveEmployee();
break;
case MenuOption.EditEmployee:
_employeeRepository.UpdateEmployee();
break;
case MenuOption.AddStore:
AddStore();
break;
case MenuOption.Exit:
Exit();
_running = false;
break;
default:
break;
}
}
}
public void ShowDistricts()
{
List<District> districts = _districtRepository.GetDistricts();
districts.ForEach(district => Console.WriteLine(district.Name));
Console.Write("Press enter to exit;");
Console.ReadLine();
}
public void ShowEmployees()
{
List<Employee> employees = _employeeRepository.GetEmployees();
foreach (var employee in employees)
{
Console.WriteLine(employee.FirstName +" "+ employee.LastName);
}
Console.Write("Press enter to exit;");
Console.ReadLine();
}
private string GetMenuAsText()
{
StringBuilder bldr = new StringBuilder();
List<string> menuOptions = Enum.GetNames<MenuOption>().ToList();
for (int i = 0; i < menuOptions.Count; i++) //start at 1, don't print the 0 option
{
bldr.AppendLine($"{i+1}. {menuOptions[i]}");
}
bldr.AppendLine();
bldr.Append("Please select a menu option: ");
return bldr.ToString();
}
public void Exit()
{
Console.WriteLine("Exiting...");
}
private void AddStore()
{
Console.WriteLine("Add a Store/District");
Console.ReadLine();
}
}