public IActionResult checkavalabilty(checkVM ch)
        {
            String SURGERYROOMName = HttpContext.Session.GetString("SRoomname");

            var NameRexist = _asu.Hospital_Facilities.Where(f => f.Type.Substring(0, 4) == "Room")
                             .Select(s => new Hospital_Facility {
                Type = s.Type
            })
                             .ToList();
            var NameSurgeryRexist = _asu.Hospital_Facilities.Where(f => f.Type.Substring(0, 6) == "Surgery")
                                    .Select(s => new Hospital_Facility {
                Type = s.Type
            })
                                    .ToList();

            int y = 0; //flag

            foreach (var x in NameRexist)
            {
                var HID           = _asu.Hospital_Facilities.Where(f => f.Type == x.Type).Select(s => s.Id).Single();
                var availableroom = _asu.Facility_Reservations.Where(f => f.Hospital_Facility_Id == HID)
                                    .Select(s => new { date = s.End_Hour, date1 = s.Start_Hour }).ToList();
                //if(availableroom ==)
                foreach (var V in availableroom)
                {
                    DateTime parse1 = DateTime.Parse(ch.From);
                    DateTime parse2 = DateTime.Parse(ch.To);
                    DateTime parse3 = DateTime.Parse(V.date);
                    DateTime parse4 = DateTime.Parse(V.date1);
                    if ((parse1 > parse3) || (parse2 < parse4))
                    {
                        y = 1;
                    }
                    else
                    {
                        y = 2;
                        break;
                    }
                }
                if (y == 1 || y == 0)
                {
                    // TempData["roomname"] = _asu.Hospital_Facilities.Where(f => f.Id == HID).Select(s => s.Type).Single();
                    var roomname = _asu.Hospital_Facilities.Where(f => f.Id == HID).Select(s => s.Type).Single();

                    ViewBag.Roomname    = roomname;
                    ViewBag.surgeryroom = SURGERYROOMName;
                    HttpContext.Session.SetString("Roomname", roomname);
                    HttpContext.Session.SetString("START", ch.From);
                    HttpContext.Session.SetString("END", ch.To);

                    return(View());
                }
                y = 0;
            }

            ViewBag.UserMessage = "This room is not available";
            return(View());
        }
        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 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");
            }
        }