public ActionResult Appointment(string id = "", int AppointmentId = 0, string status = "", string fromDate = "", string toDate = "", string msg = "")
        {
            int DoctorId = int.Parse(new EncryptDecrypt().Decrypt(id));

            DoctorAppointmentViewModel data = new DoctorAppointmentViewModel();

            AppointmentAPIController aController = new AppointmentAPIController();
            ReturnObject             ro          = new ReturnObject();

            using (var db = new ddiarydbEntities())
            {
                var doctor = db.Doctor_Master.Where(x => x.Doctor_id == DoctorId).FirstOrDefault();

                if (AppointmentId > 0)
                {
                    ro = aController.Update_Appointment(AppointmentId, status, msg);
                }

                var appointments = new List <Appointment>();

                ro = aController.Get_Appointments(0, DoctorId, fromDate, toDate);

                try
                {
                    appointments = (List <Appointment>)ro.data2;
                }
                catch (Exception)
                {
                    appointments = null;
                }

                if (doctor != null)
                {
                    data.Doctor = new DoctorViewModel().DoctorModel_to_ViewModel(doctor);

                    data.Appointments = new List <AppointmentViewModel>();
                    foreach (var item in appointments)
                    {
                        var temp = item.PatientName.Split(' ');
                        if (temp.Length > 1)
                        {
                            item.SessionId = temp[0].Substring(0, 1) + temp[1].Substring(0, 1);
                        }
                        else
                        {
                            item.SessionId = temp[0].Substring(0, 1);
                        }

                        data.Appointments.Add(new AppointmentViewModel().AppointmentModel_to_ViewModel(item));
                    }
                }
            }

            return(View(data));
        }
        public ActionResult Booking(AppointmentViewModel appointment)
        {
            appointment.Status = "Pending";

            var startend = appointment.SessionId.Split('-');

            var date = Convert.ToDateTime(appointment.DateStart);

            var datetimeStart = date.ToShortDateString() + " " + startend[0];
            var datetimeEnd   = date.ToShortDateString() + " " + startend[1];

            appointment.DateStart = DateTime.Parse(datetimeStart);
            appointment.DateEnd   = DateTime.Parse(datetimeEnd);

            appointment.SessionId = appointment.DateStart.ToString("ddMMyyyyHHmm") + appointment.DateEnd.ToString("HHmm");

            try
            {
                using (var db = new ddiarydbEntities())
                {
                    Appointment obj = new MappingService().Map <AppointmentViewModel, Appointment>(appointment);
                    obj.DoctorId = int.Parse(new EncryptDecrypt().Decrypt(appointment.Doctor.DoctorId_Encrypt));

                    //db.Appointments.Add(obj);
                    //db.SaveChanges();
                    AppointmentAPIController aController  = new AppointmentAPIController();
                    ReturnObject             returnObject = new ReturnObject();

                    if (appointment.Id != 0)
                    {
                        returnObject = aController.Update_Appointment(obj);
                    }
                    else
                    {
                        returnObject = aController.Insert_Appointment(obj);
                    }

                    try
                    {
                        if (returnObject != null)
                        {
                            Appointment a = (Appointment)returnObject.data1;

                            var doctor = db.Doctor_Master.Where(x => x.Doctor_id == obj.DoctorId).FirstOrDefault();

                            TempData["DoctorName"] = doctor.Doctor_name;

                            string id = new EncryptDecrypt().Encrypt(a.Id.ToString());

                            return(Redirect("AppointmentDetails?id=" + id));
                        }

                        return(Redirect("Booking?id=" + appointment.Doctor.DoctorId_Encrypt));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, "Something Wrong.!");
                        return(View(appointment));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "Something Wrong.!");
                return(View(appointment));
            }
        }