private void GetLists(AppointmentDataModel dt)
        {
            CASDatabaseEntities   db    = new CASDatabaseEntities();
            List <SelectListItem> lists = new List <SelectListItem>();
            List <SelectListItem> listp = new List <SelectListItem>();
            var getSpecialization       = db.SpecializationDatas.ToList();

            foreach (var item in getSpecialization)
            {
                lists.Add(new SelectListItem
                {
                    Text  = item.SpecializationName,
                    Value = item.SpecializationID.ToString()
                });
            }
            dt.ListSpecialization = lists;
            if (dt.ListSpecialization != null)
            {
                var getPhysician = db.Physicians.ToList();

                foreach (var item in getPhysician)
                {
                    listp.Add(new SelectListItem
                    {
                        Text  = item.FirstName + " " + item.LastName,
                        Value = item.PhysicianID.ToString()
                    });
                }
                dt.ListPhysician = listp;
            }
        }
        public ActionResult SendMessages()
        {
            CASDatabaseEntities         db   = new CASDatabaseEntities();
            List <AppointmentDataModel> list = new List <AppointmentDataModel>();
            AppointmentDataModel        dt   = new AppointmentDataModel();

            int ID = Convert.ToInt32(Session["ID"]);;

            var getDetails = from a in db.Appointments
                             join p in db.Physicians
                             on a.PhysicianID equals p.PhysicianID
                             where (a.PatientID == ID && a.AppointmentStatus == "Accepted")
                             select new
            {
                p.FirstName,
                p.LastName,
                a.AppointmentID,
                a.AppointmentDate
            };

            foreach (var item in getDetails)
            {
                list.Add(new AppointmentDataModel
                {
                    AppointmentID   = item.AppointmentID,
                    PhysicianName   = item.FirstName + " " + item.LastName,
                    AppointmentDate = item.AppointmentDate,
                });
            }
            dt.ListData = list;
            return(View(dt));
        }
        public ActionResult MakeAppointments(AppointmentDataModel dt)
        {
            CASDatabaseEntities db             = new CASDatabaseEntities();
            Appointment         objAppointment = new Appointment();

            var id      = Convert.ToInt32(Session["UserID"]);
            var getData = db.Patients.Where(m => m.UserID == id).FirstOrDefault();

            if (ModelState.IsValid)
            {
                GetLists(dt);
                if (getData != null)
                {
                    if (dt.AppointmentDate.DayOfWeek == 0 || (dt.AppointmentDate.Hour < 9 || dt.AppointmentDate.Hour > 17))
                    {
                        ViewBag.text = "Please Enter Time Between 9 AM and 5 PM";
                    }
                    else if (dt.AppointmentDate.Date < DateTime.Today)
                    {
                        ViewBag.text = "Please Enter a Valid Date";
                    }
                    else
                    {
                        objAppointment.PatientID         = getData.PatientID;
                        objAppointment.PhysicianID       = dt.PhysicianID;
                        objAppointment.Subject           = dt.Subject;
                        objAppointment.Description       = dt.Description;
                        objAppointment.AppointmentDate   = dt.AppointmentDate;
                        objAppointment.AppointmentStatus = "Requested";

                        db.Appointments.Add(objAppointment);
                        db.SaveChanges();
                        ViewBag.text = "Appointment Requested";
                    }
                }
                else
                {
                    ViewBag.text = "Cannot Request Appointment";
                }
            }
            return(View(dt));
        }
        public ActionResult ViewAppointment()
        {
            CASDatabaseEntities         db   = new CASDatabaseEntities();
            List <AppointmentDataModel> list = new List <AppointmentDataModel>();
            AppointmentDataModel        dt   = new AppointmentDataModel();

            int ID = Convert.ToInt32(Session["ID"]);

            var getDetails = (from a in db.Appointments
                              join p in db.Patients
                              on a.PatientID equals p.PatientID
                              where a.PhysicianID == ID
                              select new
            {
                p.FirstName,
                p.LastName,
                p.Gender,
                a.AppointmentID,
                a.Subject,
                a.Description,
                a.AppointmentDate,
                a.AppointmentStatus
            }).OrderBy(a => a.AppointmentDate);

            foreach (var item in getDetails)
            {
                list.Add(new AppointmentDataModel
                {
                    AppointmentID     = item.AppointmentID,
                    PatientName       = item.FirstName + " " + item.LastName,
                    PatientGender     = item.Gender,
                    Subject           = item.Subject,
                    Description       = item.Description,
                    AppointmentDate   = item.AppointmentDate,
                    AppointmentStatus = item.AppointmentStatus,
                });
            }
            dt.ListData = list;

            return(View(dt));
        }
        public ActionResult ViewAppointments()
        {
            CASDatabaseEntities         db   = new CASDatabaseEntities();
            List <AppointmentDataModel> list = new List <AppointmentDataModel>();
            AppointmentDataModel        dt   = new AppointmentDataModel();

            var id      = Convert.ToInt32(Session["UserID"]);
            var getData = db.Patients.Where(m => m.UserID == id).FirstOrDefault();

            if (getData != null)
            {
                var getDetails = from a in db.Appointments
                                 join p in db.Physicians
                                 on a.PhysicianID equals p.PhysicianID
                                 where a.PatientID == getData.PatientID
                                 select new
                {
                    p.FirstName,
                    p.LastName,
                    a.Subject,
                    a.Description,
                    a.AppointmentDate,
                    a.AppointmentStatus
                };

                foreach (var item in getDetails)
                {
                    list.Add(new AppointmentDataModel
                    {
                        PhysicianName     = item.FirstName + " " + item.LastName,
                        Subject           = item.Subject,
                        Description       = item.Description,
                        AppointmentDate   = item.AppointmentDate,
                        AppointmentStatus = item.AppointmentStatus,
                    });
                }
                dt.ListData = list;
            }
            return(View(dt));
        }
        public ActionResult MakeAppointments()
        {
            CASDatabaseEntities  db = new CASDatabaseEntities();
            AppointmentDataModel dt = new AppointmentDataModel();

            /*List<SelectListItem> list = new List<SelectListItem>();
             *
             * var getData = db.SpecializationDatas.ToList();
             *
             * foreach (var item in getData)
             * {
             *  list.Add(new SelectListItem
             *  {
             *      Text = item.SpecializationName,
             *      Value = item.SpecializationID.ToString()
             *  });
             * }
             * dt.ListSpecialization = list;*/
            GetLists(dt);
            dt.AppointmentDate = DateTime.Now;
            return(View(dt));
        }
        public ActionResult UpdateAppointment(int?ID, string str)
        {
            CASDatabaseEntities  db             = new CASDatabaseEntities();
            AppointmentDataModel dt             = new AppointmentDataModel();
            Appointment          objAppointment = new Appointment();

            var id      = Convert.ToInt32(ID);
            var getData = db.Appointments.Where(m => m.AppointmentID == id).FirstOrDefault();

            if (str == "Accept")
            {
                getData.AppointmentStatus = "Accepted";
                Session["Accept"]         = "Accepted";
            }
            else
            {
                getData.AppointmentStatus = "Rejected";
            }
            dt.AppointmentStatus = getData.AppointmentStatus;
            db.SaveChanges();
            return(RedirectToAction("ViewAppointment", "Physician"));
        }