public ActionResult CreateSchedule(FormCollection collection)
        {
            // how to get dropdown value
            var classes  = db.getClassActiveList();
            var teachers = db.getTeacherList();
            var rooms    = db.getRoomList();

            var scheduleViewModel = new ScheduleViewModel
            {
                Classes  = classes,
                Teachers = teachers,
                Rooms    = rooms
            };

            Schedule schedule = new Schedule();


            var selectedTeacher = Convert.ToInt32(collection["SelectedTeacherId"]);
            var selectedCLass   = Convert.ToInt32(collection["SelectedClassId"]);
            var selectedRoom    = Convert.ToInt32(collection["SelectedRoomId"]);

            ViewBag.tid = selectedTeacher;
            ViewBag.cid = selectedCLass;
            ViewBag.rid = selectedRoom;

            DateTime classDate = Convert.ToDateTime(collection["classDate"]);

            ViewBag.date = classDate.ToString("yyyy-MM-dd");
            TimeSpan timePicker = TimeSpan.Parse(collection["picker"]);

            ViewBag.time = timePicker.Hours + ":" + timePicker.Minutes;
            XDocument xd           = db.getAvailability(selectedTeacher);
            string    dayOftheWeek = classDate.DayOfWeek.ToString();
            TimeSpan  sTime;
            TimeSpan  eTime;

            Yoga_User u = db.getUserById(selectedTeacher);

            if (DateTime.Now.Date > classDate)
            {
                ViewBag.message = "<p><span style=\"color:red\">Date Error:</span> Can't Select Dates in the Past</p>";
                return(View(scheduleViewModel));
            }


            try
            {
                sTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("Start").Value);
                eTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("End").Value);
            }
            catch
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " is unavailable " + dayOftheWeek.ToLower() + ".";
                return(View(scheduleViewModel));
            }
            Class    c        = db.getClass(selectedCLass);
            TimeSpan classEnd = timePicker.Add(c.Class_Length);


            if (sTime > timePicker)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " starts " + dayOftheWeek + " at " + sTime.Hours + ":" + sTime.Minutes.ToString("00");
                return(View(scheduleViewModel));
            }

            if (timePicker > eTime)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " ends " + dayOftheWeek + " at " + eTime.Hours + ":" + eTime.Minutes.ToString("00");
                return(View(scheduleViewModel));
            }

            if (classEnd > eTime)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " ends " + dayOftheWeek + " at " + eTime.Hours + ":" + eTime.Minutes.ToString("00") + "<br/>" +
                                  "Class End: " + classEnd.Hours + ":" + classEnd.Minutes.ToString("00") + "</p>";
                return(View(scheduleViewModel));
            }

            IEnumerable <Schedule> sList = db.getScheduleByRoomAndDay(selectedRoom, classDate);

            foreach (Schedule s in sList)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd || classEnd > s.Start_Time && classEnd <= sEnd)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Room Error: </span>" + s.Room.Room_Name + " is unavailable from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }

            IEnumerable <Schedule> sListbyTeacher = db.getScheduleByTeacherAndDay(selectedTeacher, classDate);

            foreach (Schedule s in sListbyTeacher)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd || classEnd > s.Start_Time && classEnd <= sEnd)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " already scheduleed from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }



            // Add course length to timeSpan? no sure working
            var classTime = db.getClass(selectedCLass).Class_Length;

            timePicker.Add(classTime);


            schedule.Teacher_Id      = selectedTeacher;
            schedule.Class_Id        = selectedCLass;
            schedule.Room_Id         = selectedRoom;
            schedule.Class_Date      = classDate;
            schedule.Schedule_Status = "ACTIVE";
            schedule.Start_Time      = timePicker;


            db.CreateSchedule(schedule);

            return(RedirectToAction("ScheduleList"));
        }