// GET: Administrator/Appointment
        public ActionResult Index()
        {
            Session["AvailableSchedule"] = null;
            var model = new SearchViewModel
            {
                Specialties = new SpecialtyAppService().GetAllSpecialty(),
                Medics = new EmployeeAppService().GetAllMedics()
            };
            var ci = new CultureInfo("es-CO");

            model.AvailableSlot = new List<TimeSlotViewModel>();
            model.EmployeeId = -1;
            model.SpecialtyId = -1;
            model.GeoCityId = "-1";
            model.FromDate = DateTime.Now.Date.ToString("dd/MM/yyyy",ci);
            model.ToDate = "";
            model.PatientId = -1;



            return View(model);
        }
        public ActionResult Index(SearchViewModel model)
        {
            var ci = new CultureInfo("es-CO");

            model.Specialties = new SpecialtyAppService().GetAllSpecialty();
            model.Medics = new EmployeeAppService().GetAllMedics();

            List<TimeSlot> lst = new TimeSlotAppService().GetAllTimeSlotWithoutAppoitment();

            if (model.EmployeeId != -1)
            {
                lst = ApplyFilterEmployee(lst, model.EmployeeId);
            }

                 if (model.SpecialtyId != -1)
            {
                lst = ApplyFilterSpecialty(lst, model.SpecialtyId);
            }


            if (!String.IsNullOrEmpty(model.GeoCityId) || model.GeoCityId!= "-1")
            {
                lst = ApplyFilterCity(lst, model.GeoCityId);
            }

            if (!String.IsNullOrEmpty(model.FromDate) && !String.IsNullOrEmpty(model.ToDate))
            {
               

                var fromDate = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", ci);
                var toDate = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", ci);

                lst = ApplyFilterDate(lst, fromDate,toDate);
            }





            model.AvailableSlot = new List<TimeSlotViewModel>();

            System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
            foreach (var itm in lst)
            {

                var emp = new EmployeeAppService().GetEmployee(itm.Schedule.EmployeeId);

                var itmVm = new TimeSlotViewModel
                {
                    ScheduleId = itm.ScheduleId,
                    MonthName = itm.Schedule.Month,
                    TimeSlotId = itm.TimeSlotId,
                    OfficeId = itm.OfficeId,
                    Day = itm.Day,
                    StartTime = itm.StartTime,
                    EndTime = itm.EndTime,
                    StartTimeText = itm.StartTime.ToShortTimeString(),
                    EndTimeText = itm.EndTime.ToShortTimeString(),
                    OfficeAddress = string.Format("Medico:{0}({1}) {2},{3}", emp.FullName, itm.Office.Address, itm.Office.Number, itm.Office.GeoCity.Name),
                    DayName = string.Format("{0},{1} de {2} de {3}", new DateTime(itm.Schedule.Year, itm.Schedule.Month, itm.Day).DayOfWeek.ToString(ci), itm.Day,mfi.GetMonthName(itm.Schedule.Month).ToString(),itm.Schedule.Year) 

                };

                


                model.AvailableSlot.Add(itmVm);
            }


            Session["AvailableSchedule"] = model.AvailableSlot;
            return View(model);
        }