public ActionResult Index()
        {
            if (Session["doctorid"] == null)
            {
                Response.Redirect("../Login/Authenticate");
            }

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

            var dblist = db.tblAppointmentSlots.Where(x => x.intDoctorID == did).ToList();
            List <AppointmentSlotModel> list = new List <AppointmentSlotModel>();

            foreach (tblAppointmentSlot S in dblist)
            {
                AppointmentSlotModel SA = new AppointmentSlotModel();
                SA.SlotID    = S.intSlotID;
                SA.DoctorID  = (int)S.intDoctorID;
                SA.ClinicID  = (int)S.intClinicID;
                SA.Date      = (DateTime)S.dtmDate;
                SA.StartTime = (DateTime)S.dtmStartTime;
                SA.EndTime   = (DateTime)S.dtmEndTime;
                SA.Status    = S.strStatus;

                list.Add(SA);
            }
            return(View(list));
        }
        public ActionResult DoctorCancel()
        {
            if (Session["doctorid"] == null)
            {
                Response.Redirect("../Login/Authenticate");
            }

            int      did    = Convert.ToInt32(Session["doctorid"].ToString());
            DateTime dt     = DateTime.Now;
            var      dblist = db.tblAppointmentSlots.Where(x => (x.intDoctorID == did && x.dtmStartTime > dt)).ToList();

            var aplist = new List <AppointmentModel>();



            foreach (tblAppointmentSlot S in dblist)
            {
                AppointmentSlotModel SA = new AppointmentSlotModel();

                var app = db.tblAppointments.Where(x => x.intSlotID == S.intSlotID);
                foreach (tblAppointment P in app)
                {
                    AppointmentModel M = new AppointmentModel()
                    {
                        AppointmentID = P.intAppointmentID, AppotimentTakenTime = (DateTime)P.dtmAppotimentTakenTime, IsNewCase = (bool)P.blnIsNewCase, MemberID = (int)P.intMemberID, Notes = P.strNotes, OldCaseNo = P.strOldCaseNo, PatientAge = (int)P.intPatientAge, PatientGender = P.strPatientGender, PatientName = P.strPatientName, SlotID = (int)P.intSlotID
                    };
                    aplist.Add(M);
                }
            }
            return(View(aplist));
        }
        public ActionResult Delete(AppointmentSlotModel P)
        {
            var d = db.tblAppointmentSlots.SingleOrDefault(x => x.intSlotID == P.SlotID);

            db.tblAppointmentSlots.Remove(d);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            tblAppointmentSlot   t = db.tblAppointmentSlots.SingleOrDefault(x => x.intSlotID == id);
            AppointmentSlotModel P = new AppointmentSlotModel()
            {
                SlotID    = t.intSlotID,
                DoctorID  = (int)t.intDoctorID,
                ClinicID  = (int)t.intClinicID,
                Date      = (DateTime)t.dtmDate,
                StartTime = (DateTime)t.dtmStartTime,
                EndTime   = (DateTime)t.dtmEndTime,
                Status    = t.strStatus,
            };

            return(View(P));
        }
        public ActionResult Edit(AppointmentSlotModel am)
        {
            tblAppointmentSlot a = db.tblAppointmentSlots.SingleOrDefault(x => x.intSlotID == am.SlotID);


            if (a != null)
            {
                a.intSlotID    = am.SlotID;
                a.intDoctorID  = am.DoctorID;
                a.intClinicID  = am.ClinicID;
                a.dtmDate      = am.Date;
                a.dtmStartTime = am.StartTime;
                a.dtmEndTime   = am.EndTime;
                a.strStatus    = am.Status;

                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(AppointmentSlotModel AS, FormCollection frm)
        {
            String gap = frm["Gap"];

            tblAppointmentSlot a = new tblAppointmentSlot();

            a.intSlotID    = AS.SlotID;
            a.intDoctorID  = Convert.ToInt32(Session["doctorid"]);
            a.intClinicID  = AS.ClinicID;
            a.dtmDate      = AS.Date;
            a.dtmStartTime = AS.StartTime;

            a.dtmEndTime = AS.EndTime;

            a.dtmStartTime = a.dtmDate;
            a.dtmStartTime = a.dtmStartTime.Value.AddHours(AS.StartTime.Hour);
            a.dtmStartTime = a.dtmStartTime.Value.AddMinutes(AS.StartTime.Minute);


            a.dtmEndTime = a.dtmDate.Value.AddHours(AS.EndTime.Hour);
            a.dtmEndTime = a.dtmEndTime.Value.AddMinutes(AS.EndTime.Minute);

            a.strStatus = AS.Status;

            DateTime st  = a.dtmStartTime.Value;
            DateTime end = a.dtmEndTime.Value;

            while (st <= end)
            {
                DateTime en = st.AddMinutes(Convert.ToInt32(gap));
                a.dtmStartTime = st;
                a.dtmEndTime   = en;// a.dtmEndTime.Value.AddMinutes();
                db.tblAppointmentSlots.Add(a);
                db.SaveChanges();

                st = en;
            }


            return(RedirectToAction("Index"));
        }