public IActionResult CreateAppointment(PatientAppointmentReferral PAR)
 {
     //IPatientAppointmentReferralRepository IPAR;
     if (ModelState.IsValid)
     {
         //IPAR.createPAR(PAR);
         repository.CreatePAR(/*new */ PAR);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
        public IActionResult CreatingAppointment(PatientAppointmentReferral PAR, string RequestedDate)
        {
            List <string> newList = new List <string>();

            //this preloads the data for the appointment page
            ViewBag.Dates     = newList;
            PAR.Decision      = "Booked";
            PAR.RequestedTime = RequestedDate.Substring(11); //PAR.RequestedDate.TimeOfDay.ToString();
            if (PAR.RequestedDate.Date >= DateTime.Now.Date && (PAR.RequestedDate.DayOfWeek.ToString() != "Saturday" || PAR.RequestedDate.DayOfWeek.ToString() != "saturday") || (PAR.RequestedDate.DayOfWeek.ToString() != "Sunday") || (PAR.RequestedDate.DayOfWeek.ToString() != "sunday"))
            {
                if (ModelState.IsValid)
                {
                    Appointment appointment = new Appointment();
                    appointment.AppointmentDate = DateTime.Parse(RequestedDate);
                    //appointment.AppointmentTime = PAR.RequestedTime;
                    appointment.AppointmentTime = RequestedDate.Substring(11);
                    appointment.AppointmentType = "Doctor's Surgery";
                    appointment.County          = PAR.County;
                    appointment.CurrentDate     = PAR.CurrentDate;
                    appointment.Diagnosis       = "";
                    appointment.DOB             = PAR.DOB;
                    appointment.PatientFullName = PAR.Name;
                    appointment.Postcode        = PAR.Postcode;
                    appointment.Region          = PAR.Region;
                    appointment.StreetName      = PAR.StreetName;
                    appointment.StreetNumber    = PAR.StreetNumber;
                    appointment.Symptoms        = PAR.Symptoms;
                    appointment.AppointmentMedicalProfessional = PAR.MedicalPersonnel;

                    //this checks if users are Medical personnel or not
                    if (HttpContext.Session.GetString("Name") != "" && (HttpContext.Session.GetString("Type") == "Doctor" || HttpContext.Session.GetString("Type") == "Nurse"))
                    {
                        try
                        {
                            //this checks if usersis already in the database and adds the appointment to the appropriate database table and displays the appropriate message
                            Account accounts = AccountRepository.Accounts.FirstOrDefault(a => a.Name == appointment.PatientFullName);
                            if (accounts == null)
                            {
                                PARrepository.CreatePAR(PAR);
                                TempData["Message"] = "Appointment Created";
                            }
                            else
                            {
                                //Account account = AccountRepository.Accounts.FirstOrDefault(a => a.Name == appointment.PatientFullName);
                                appointment.UserReferralID = accounts.ID;
                                AppointmentRepository.CreateAppointment(appointment);
                                TempData["Message"] = "Appointment Created";
                            }
                        }
                        catch
                        {
                            //this adds a valid appointment as a guest appointment
                            PARrepository.CreatePAR(PAR);
                        }
                        //this returns the user to the practitioners index view
                        return(RedirectToAction("Index", "Practitioners"));
                    }
                    else if ((HttpContext.Session.GetString("Name") != "" || HttpContext.Session.GetString("Name") != null) && HttpContext.Session.GetString("Type") == "Patient")
                    {
                        //this adds a logged in user's appointment as a logged in user appointment, displays the apppropriate message and redirects the user to their respected homepage
                        Account account = HttpContext.Session.getJson <Account>("Account");
                        appointment.UserReferralID = account.ID;
                        AppointmentRepository.CreateAppointment(appointment);
                        TempData["Message"] = "Appointment Created";
                        return(RedirectToAction("Index", "Patient"));
                    }
                    else
                    {
                        //this adds a guest user's appointment as a guest appointment, displays the apppropriate message and redirects the user to their respected homepage
                        PARrepository.CreatePAR(PAR);
                        TempData["Message"] = "Appointment Created";
                        return(RedirectToAction("Index", "Appointment"));
                    }
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }