public IActionResult Search(SearchVm ob)
        {
            Facility_Reservation FR = new Facility_Reservation();
            var Nameexist           = _asu.Patients.ToList().Any(f => f.Name == ob.patientName);

            if (Nameexist)
            {
                var ID         = _asu.Patients.Where(f => f.Name == ob.patientName).Select(s => s.Id).Single();
                var NamePexist = _asu.Facility_Reservations.ToList().Any(f => f.Patient_Id == ID);
                if (NamePexist)
                {
                    /*
                     *              var Startavailable = _asu.Facility_Reservations.Where(f => f.Patient_Id == ID)
                     *                  .Select(s => s.Start_Hour).Single();
                     *              var Endavailable = _asu.Facility_Reservations.Where(f => f.Patient_Id == ID)
                     *                .Select(s => s.End_Hour).Single();
                     *
                     * var Endavailable = _asu.Facility_Reservations.Where(f => f.Patient_Id == ID)
                     *              .Select(s =>new { s.End_Hour ,s.Start_Hour}).ToList();
                     * DateTime parse1 = DateTime.Parse(Startavailable);
                     * DateTime parse2 = DateTime.Parse(Endavailable);
                     */
                    var Endavailable = _asu.Facility_Reservations.Where(f => f.Patient_Id == ID)
                                       .Select(s => new { dates = s.Start_Hour, dateE = s.End_Hour, name = s.Id })
                                       .OrderByDescending(w => w.dateE).FirstOrDefault();
                    //.ToList();
                    //foreach (var V in Endavailable)
                    //{
                    DateTime parse3 = DateTime.Parse(Endavailable.dates);
                    DateTime parse4 = DateTime.Parse(Endavailable.dateE);
                    //int i = V.name;
                    if ((parse3 <= ob.Today && ob.Today <= parse4))
                    {
                        var roomnumber = _asu.Facility_Reservations
                                         .Where(F => F.Id == Endavailable.name)
                                         .Select(s => s.Hospital_Facility_Id).Single();
                        TempData["room"] = _asu.Hospital_Facilities.Where(t => t.Id == roomnumber)
                                           .Select(S => S.Type).Single();
                        ViewBag.DD = TempData["room"];
                        return(View());
                        // return Redirect("/Front_desk/Searchresult");
                    }
                    else
                    {
                        ViewBag.Not = "This patient is not in our hospital.";
                        return(View());
                        //return Redirect("/Front_desk/NotAvailable");
                    }
                    //}
                }
                ViewBag.Not = "This patient is not in our hospital.";
                return(View());
                //return Redirect("/Front_desk/NotAvailable");
            }
            ViewBag.Not = "This patient is not in our hospital.";
            return(View());
            //return Redirect("/Front_desk/NotAvailable");
        }
        public IActionResult Delete(delete vm, checkVM ch)
        {
            var NameExist = _asu.Patients.ToList().Any(u => u.Name == vm.PatientName);

            if (NameExist)
            {
                Facility_Reservation FR = new Facility_Reservation();

                var PatientName = _asu.Patients.Where(f => f.Name == vm.PatientName)
                                  .Select(s => s.Id).Single();
                var NameExistreservation = _asu.Facility_Reservations.ToList().Any(u => u.Patient_Id == PatientName);
                //var RoomID = _asu.Facility_Reservations.Where(f => f.Patient_Id == PatientName)
                //.OrderByDescending(d=>d);
                if (NameExistreservation)
                {
                    var h = _asu.Facility_Reservations.Where(f => f.Patient_Id == PatientName)
                            .Select(s => new Facility_Reservation {
                        Id = s.Id, Staff_Id = s.Staff_Id
                    })
                            .OrderByDescending(s => s.Id)
                            .FirstOrDefault();
                    String ROOMName = HttpContext.Session.GetString("Roomname");
                    String start    = HttpContext.Session.GetString("START");
                    String end      = HttpContext.Session.GetString("END");
                    var    HID      = _asu.Hospital_Facilities.Where(f => f.Type == ROOMName).Select(s => s.Id).Single();
                    FR.Start_Hour           = start; //ob.From;
                    FR.End_Hour             = end;
                    FR.Hospital_Facility_Id = HID;
                    //FR.Hospital_Facility_Id =no ;
                    FR.Patient_Id = PatientName;
                    FR.Staff_Id   = h.Staff_Id;
                    _asu.Add(FR);
                    _asu.SaveChanges();
                    int x     = h.Id;
                    var model = _asu.Facility_Reservations.Find(x);
                    _asu.Remove(model);
                    _asu.SaveChanges();
                    ViewBag.UserMessage3 = "Patient is transferred successfully";

                    return(View());
                }
                else
                {
                    ViewBag.fail = "This Patient doesnt have a reservation";
                    return(View());
                }
            }
            else
            {
                ViewBag.fail = "This Patient doesnt have a reservation";
                return(View());
            }
        }
        public IActionResult Event(mainVM m)
        {
            Facility_Reservation FR = new Facility_Reservation();
            Hospital_Facility    H  = new Hospital_Facility();
            var ID = _asu.Hospital_Facilities.Where(f => f.Type == m.Room_Id).Select(s => s.Id).Single();
            var h  = _asu.Facility_Reservations.Include(p => p.Patient).Where(f => f.Hospital_Facility_Id == ID)
                     .OrderByDescending(s => s.End_Hour).ToList();

            ViewBag.Roomnumber = m.Room_Id;
            ViewBag.D1         = h;



            return(View());
        }
        public IActionResult Roomreservation(roomVM ob, checkVM ch)
        {
            String ROOMName         = HttpContext.Session.GetString("Roomname");
            String start            = HttpContext.Session.GetString("START");
            String end              = HttpContext.Session.GetString("END");
            String SURGERYROOMName  = HttpContext.Session.GetString("SRoomname");
            String surgerystart     = HttpContext.Session.GetString("STARTSurgery");
            String surgeryend       = HttpContext.Session.GetString("ENDSurgery");
            Facility_Reservation FR = new Facility_Reservation();
            Facility_Reservation F  = new Facility_Reservation();
            Payment P          = new Payment();
            Payment P1         = new Payment();
            var     NamePexist = _asu.Patients.ToList().Any(f => f.Name == ob.PatientName);
            var     NameSexist = _asu.Staff.ToList().Any(F => F.Name == ob.DoctorName);

            var      surgeryprice   = _asu.Follow_Ups_Types.Where(f => f.Name == "Surgery").Select(s => s.Price).Single();
            var      roomprice      = _asu.Follow_Ups_Types.Where(f => f.Name == "Room").Select(s => s.Price).Single();
            var      RoompriceId    = _asu.Follow_Ups_Types.Where(f => f.Name == "Room").Select(s => s.Id).Single();
            var      surgeryId      = _asu.Follow_Ups_Types.Where(f => f.Name == "Surgery").Select(s => s.Id).Single();
            DateTime parse1         = DateTime.Parse(start);
            DateTime parse2         = DateTime.Parse(end);
            var      Duration       = parse2 - parse1;
            int      days           = Duration.Days + 1;
            int      Totalroomprice = days * roomprice;

            var HID = _asu.Hospital_Facilities.Where(f => f.Type == ROOMName).Select(s => s.Id).Single();

            if (NamePexist)
            {
                TempData["Patient_Id"] = _asu.Patients.Where(f => f.Name == ob.PatientName).Select(s => s.Id).Single();
                if (NameSexist)
                {
                    //string start = TempData["Start"].ToString();
                    //string end = TempData["end"].ToString();
                    //int no = (int)TempData["HID"];
                    TempData["Staff_Id"] = _asu.Staff.Where(f => f.Name == ob.DoctorName).Select(s => s.Id).Single();
                    if (SURGERYROOMName == null)
                    {
                        FR.Start_Hour           = start; //ob.From;
                        FR.End_Hour             = end;
                        FR.Hospital_Facility_Id = HID;
                        //FR.Hospital_Facility_Id =no ;
                        FR.Patient_Id = (int)TempData["Patient_Id"];
                        FR.Staff_Id   = (int)TempData["Staff_Id"];
                        _asu.Add(FR);
                        P1.Patient_Id        = (int)TempData["Patient_Id"];
                        P1.Money             = Totalroomprice;
                        P1.Follow_Up_Type_Id = RoompriceId;
                        _asu.Add(P1);
                        _asu.SaveChanges();
                        ViewBag.UserMessage2 = "Done";
                        return(View());
                    }
                    else
                    {
                        var SHID = _asu.Hospital_Facilities.Where(f => f.Type == SURGERYROOMName).Select(s => s.Id).Single();
                        F.Start_Hour           = surgerystart; //ob.From;
                        F.End_Hour             = surgeryend;
                        F.Hospital_Facility_Id = SHID;
                        //FR.Hospital_Facility_Id =no ;
                        F.Patient_Id = (int)TempData["Patient_Id"];
                        F.Staff_Id   = (int)TempData["Staff_Id"];
                        _asu.Add(F);
                        FR.Start_Hour           = start; //ob.From;
                        FR.End_Hour             = end;
                        FR.Hospital_Facility_Id = HID;
                        //FR.Hospital_Facility_Id =no ;
                        FR.Patient_Id = (int)TempData["Patient_Id"];
                        FR.Staff_Id   = (int)TempData["Staff_Id"];

                        _asu.Add(FR);

                        P.Patient_Id        = (int)TempData["Patient_Id"];
                        P.Money             = surgeryprice;
                        P.Follow_Up_Type_Id = surgeryId;
                        _asu.Add(P);
                        P1.Patient_Id        = (int)TempData["Patient_Id"];
                        P1.Money             = Totalroomprice;
                        P1.Follow_Up_Type_Id = RoompriceId;
                        _asu.Add(P1);
                        _asu.SaveChanges();
                        ViewBag.UserMessage2 = "Done";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.UserMessage1 = "This doctor is not in our hospital";
                    return(View());
                }
            }
            else
            {
                ViewBag.UserMessage3 = "This doctor is not from the staff.";
                return(View());
                //return Redirect("/Front_desk/PatientMESSAGE");
            }
        }