-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (96 loc) · 4.05 KB
/
Program.cs
File metadata and controls
110 lines (96 loc) · 4.05 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
using FluentValidation;
using VeterinaryManagementConsole.Interfaces;
using VeterinaryManagementConsole.Models;
using VeterinaryManagementConsole.Repositories;
using VeterinaryManagementConsole.Services;
using VeterinaryManagementConsole.Utils;
using VeterinaryManagementConsole.Validators;
namespace VeterinaryManagementConsole;
public class Program
{
public static void Main(string[] args)
{
// --- 1. COMPOSITION ROOT (DEPENDENCY WIRING) ---
IEmployeeRepository employeeRepository = new EmployeeRepository();
IClientRepository clientRepository = new ClientRepository();
IPetRepository petRepository = new PetRepository();
IAppointmentRepository appointmentRepository = new AppointmentRepository();
IValidator<Client> clientValidator = new ClientValidator();
IValidator<Pet> petValidator = new PetValidator();
IValidator<Employee> employeeValidator = new EmployeeValidator();
IAuthService authService = new ServiceAuthentication(employeeRepository);
IEmployeeService employeeService = new EmployeeService(
employeeRepository,
employeeValidator
);
IClientServices clientService = new ServicesClient(clientRepository, clientValidator);
IPetService petService = new ServicesPets(petRepository, clientRepository, petValidator);
IAppointmentService appointmentService = new ServiceAppointment(
appointmentRepository,
petRepository,
employeeRepository
);
// --- 2. MAIN APPLICATION LOOP ---
bool keepRunningApp = true;
while (keepRunningApp)
{
Console.Clear();
Console.WriteLine("=== Veterinary Management System ===");
Console.WriteLine("Please log in. (or type 'exit' or 'q' to quit)");
Console.Write("Username: ");
string? username = Console.ReadLine();
if (
string.Equals(username, "exit", StringComparison.OrdinalIgnoreCase)
|| string.Equals(username, "q", StringComparison.OrdinalIgnoreCase)
)
{
keepRunningApp = false;
continue;
}
Console.Write("Password: ");
string? password = Console.ReadLine();
var loggedInEmployee = authService.Login(username ?? "", password ?? "");
if (loggedInEmployee == null)
{
Console.WriteLine("\nIncorrect credentials. Press any key to retry...");
Console.ReadKey();
continue;
}
Console.WriteLine(
$"\nWelcome, {loggedInEmployee.Name}! (Role: {loggedInEmployee.Role})"
);
Console.WriteLine("Press any key to load menu...");
Console.ReadKey();
// --- 3. ROLE-BASED MENU DISPATCHER ---
// This is where we launch the correct module and add services necessary.
switch (loggedInEmployee.Role)
{
case "Receptionist":
var receptionistMenu = new MenuReceptionist(
clientService,
petService,
appointmentService,
employeeRepository
);
receptionistMenu.Show();
break;
case "Veterinarian":
var vetMenu = new MenuVeterinarian(appointmentService, petService);
vetMenu.Show(loggedInEmployee);
break;
case "Admin":
var adminMenu = new MainAdmin(
employeeService,
employeeRepository,
employeeValidator
);
adminMenu.Show(loggedInEmployee);
break;
default:
Console.WriteLine("Error: Role not recognized. Logging out.");
Console.ReadKey();
break;
}
}
}
}