public static void ConfirmRequest(Consultation request)
 {
     if (request != null)
     {
         Console.WriteLine("Write duration of consulteation(by minutes).");
         bool t        = false;
         int  duration = 0;
         while (!t)
         {
             try
             {
                 duration = Convert.ToInt32(Console.ReadLine());
                 t        = true;
             }
             catch (FormatException)
             {
                 MessageBox.Show("Write duration of consulteation by minutes.");
             }
         }
         Consultation newConsultation = new Consultation(request.StartOfConsultation, request.StartOfConsultation.AddMinutes(duration), request.Patient);
         Doctor       myDoctor        = (Doctor)myUser;
         myDoctor.ServeAPatient(newConsultation);
         myDoctor.ListOfRequests.Remove(request);
     }
 }
 public void ServeAPatient(Consultation request)
 {
     if (request.StartOfConsultation > DateTime.Now)
     {
         this.Calendar.Add(request);
         request.Patient.Messages.Add(new Message("Your request for consultation was confirmed. \nYour consultation: " + request.StartOfConsultation.ToString().Substring(0, 16) + " - " + request.EndOfConsultation.TimeOfDay.ToString().Substring(0, 5) + "\n                   Doctor:" + this.Name + " " + this.Surname + " (" + this.Login + ")", DateTime.Now));
         this.ListOfRequests.Remove(request);
     }
     else
     {
         MessageBox.Show("You can't confirm request whith past date.");
     }
 }
        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));
            }
        }
 public void RefuseARequest(Consultation request)
 {
     request.Patient.Messages.Add(new Message("Your request for consultation on " + request.StartOfConsultation.ToString().Substring(0, 16) + " was refused.", DateTime.Now));
     ListOfRequests.Remove(request);
 }
 public void PrintRequest(Consultation request)
 {
     Console.WriteLine(request.Patient.Name + " " + request.Patient.Surname + " " + request.StartOfConsultation.ToString().Substring(0, 16));
 }