-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cs
More file actions
91 lines (84 loc) · 3.49 KB
/
Copy pathMenu.cs
File metadata and controls
91 lines (84 loc) · 3.49 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
namespace BasicContactList
{
public class Menu
{
private readonly IContactManager contactManager;
public Menu()
{
contactManager = new ContactManager();
}
public void PrintMenu()
{
Console.WriteLine("Enter 1 to Add new contact");
Console.WriteLine("Enter 2 to delete contact");
Console.WriteLine("Enter 3 to update contact");
Console.WriteLine("Enter 4 to Search contact");
Console.WriteLine("Enter 5 to Print all contacts");
Console.WriteLine("Enter 0 to Exit");
}
public void MyMenu()
{
bool exit = false;
while (!exit)
{
Console.Clear();
PrintMenu();
int option;
if (int.TryParse(Console.ReadLine(), out option))
{
switch (option)
{
case 0:
exit = true;
break;
case 1:
Console.Write("Enter contact name: ");
var name = Console.ReadLine()!;
Console.Write("Enter phone number: ");
var phoneNumber = Console.ReadLine()!;
Console.Write("Enter email: ");
var email = Console.ReadLine()!;
var contactTypeInt = Utility.SelectEnum("Select contact type:\n1 Family & Friends\n2 Work Or Business: ", 1, 2);
var contactType = (ContactType)contactTypeInt;
contactManager.AddContact(name, phoneNumber, email, contactType);
break;
case 2:
Console.Write("Enter phone number of the contact to delete: ");
string phone = Console.ReadLine()!;
contactManager.DeleteContact(phone);
break;
case 3:
Console.Write("Enter contact name: ");
var nameToEdit = Console.ReadLine()!;
Console.WriteLine("Enter phone number: ");
var phoneToEdit = Console.ReadLine()!;
Console.WriteLine("Enter email: ");
var emailToEdit = Console.ReadLine()!;
contactManager.UpdateContact(phoneToEdit, nameToEdit, emailToEdit);
break;
case 4:
Console.Write("Enter phone number of contact to search:");
var search = Console.ReadLine()!;
contactManager.GetContact(search);
break;
case 5:
contactManager.GetAllContacts();
break;
default:
Console.WriteLine("Unknown operation!");
break;
}
if (!exit)
{
HoldScreen();
}
}
}
}
private void HoldScreen()
{
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}
}