public static void MyConsole() { AllPatients = JsonConvert.DeserializeObject <List <Patient> >(File.ReadAllText(allPatientsPath)); allDoctors = JsonConvert.DeserializeObject <List <Doctor> >(File.ReadAllText(allDoctorsPath)); admin = JsonConvert.DeserializeObject <Admin>(File.ReadAllText(adminPath)); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("WELCOME TO OUR HOSPITAL :)\n"); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Active commands: " + (Command)0); for (int i = 1; i <= (int)Command.exit; i++) { Console.WriteLine(" " + (Command)i); } Command command = Command.nothing; while (command != Command.exit) { if (myUser != null) { if (myUser.Possition == "Patient") { Console.WriteLine(); PrintUser(myUser); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Active commands: " + (Command)2); for (int i = 3; i <= (int)Command.myMessages; i++) { if ((selected == null || selected.Possition != "Doctor") && (Command)i == Command.requestForConsultation) { continue; } Console.WriteLine(" " + (Command)i); } } else if (myUser.Possition == "Doctor") { Console.WriteLine(); PrintUser(myUser); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Active commands: " + (Command)2); for (int i = 3; i <= (int)Command.changePassword; i++) { Console.WriteLine(" " + (Command)i); } for (int i = (int)Command.addPatientHistory; i <= (int)Command.myCalendar; i++) { if ((selected == null || selected.Possition != "Patient") && (Command)i == Command.addPatientHistory) { continue; } Console.WriteLine(" " + (Command)i); } } else if (myUser.Possition == "Admin") { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Active commands: " + (Command)2); for (int i = 3; i <= (int)Command.changePassword; i++) { Console.WriteLine(" " + (Command)i); } for (int i = (int)Command.addDoctor; i <= (int)Command.reports; i++) { if ((selected == null || selected.Possition != "Doctor") && (Command)i == Command.deleteDoctor) { continue; } Console.WriteLine(" " + (Command)i); } Console.ForegroundColor = ConsoleColor.White; PrintUser(myUser); } if (selected != null) { Console.Write("Opened Page: "); PrintUser(selected); } } Console.ForegroundColor = ConsoleColor.White; Console.Write("$ "); String line = Console.ReadLine(); command = DetectCommand(line.Split()[0]); line = line.Replace(command.ToString(), "").Trim(); switch (command) { case Command.nothing: MessageBox.Show("Incorrect command!"); break; case Command.search: selected = Search(line); Console.WriteLine(selected); break; case Command.signIn: if (myUser == null) { SignIn(); } else { MessageBox.Show("You are already loged in."); } break; case Command.signUp: if (myUser == null) { string[] userData = SignUp(); myUser = new Patient(userData[0], userData[1], userData[2], userData[3]); try { allPatients.Add((Patient)myUser); } catch { } } else { MessageBox.Show("You are already signed up."); } break; case Command.signOut: SignOut(); break; case Command.changePassword: if (myUser != null) { ChangePassword(myUser); } break; case Command.requestForConsultation: if (myUser != null && selected != null && selected.Possition == "Doctor") { RequestForConsultation(line.Replace(command.ToString(), "").Trim()); } else { MessageBox.Show("Incorrect command."); } break; case Command.myHistory: if (myUser != null && myUser.Possition == "Patient") { myPatient = (Patient)myUser; myPatient.SeeMyHistory(); } else { MessageBox.Show("Incorrect command."); } break; case Command.myMessages: if (myUser != null && myUser.Possition == "Patient") { myPatient = (Patient)myUser; myPatient.SeeMyMessages(); } else { MessageBox.Show("Incorrect command."); } break; case Command.addPatientHistory: if (myUser != null && myUser.Possition == "Doctor" && selected.Possition == "Patient") { myDoctor = (Doctor)myUser; if (selected != null && selected.Possition == "Patient") { myDoctor.AddNoteToPatientHistory((Patient)selected, line.Replace(command.ToString(), "").Trim()); } else { MessageBox.Show("There is no patient selected."); } } else { MessageBox.Show("Incorrect command."); } break; case Command.openListOfRequests: if (myUser != null && myUser.Possition == "Doctor") { myDoctor.OpenListOfRequests(); } else { MessageBox.Show("Incorrect command."); } break; case Command.confirm: if (myUser != null && myUser.Possition == "Doctor") { ConfirmRequest(Select(myDoctor.ListOfRequests, line.Replace(command.ToString(), "").Trim())); } else { MessageBox.Show("Incorrect command."); } break; case Command.refuse: if (myUser != null && myUser.Possition == "Doctor") { Consultation request = Select(myDoctor.ListOfRequests, line.Replace(command.ToString(), "").Trim()); if (request != null) { myDoctor.RefuseARequest(request); } } else { MessageBox.Show("Incorrect command."); } break; case Command.myCalendar: if (myUser != null && myUser.Possition == "Doctor") { myDoctor.SeeMyCalendar(); } else { MessageBox.Show("Incorrect command."); } break; case Command.addDoctor: if (myUser != null && myUser.Possition == "Admin") { AddDoctor(); } else { MessageBox.Show("Incorrect command."); } break; case Command.deleteDoctor: if (myUser != null && myUser.Possition == "Admin") { if (selected != null && selected.Possition == "Doctor") { myAdmin = (Admin)myUser; myAdmin.DeleteDoctor((Doctor)selected); } else { MessageBox.Show("There is no doctor selected."); } } else { MessageBox.Show("Incorrect command."); } break; case Command.reports: if (myUser != null && myUser.Possition == "Admin") { admin.Report(); } else { MessageBox.Show("Incorrect command."); } break; } File.WriteAllText(allPatientsPath, JsonConvert.SerializeObject(AllPatients)); File.WriteAllText(allDoctorsPath, JsonConvert.SerializeObject(AllDoctors)); File.WriteAllText(adminPath, JsonConvert.SerializeObject(admin)); } }