public ActionResult DisplayQuarters()
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetAvailableQuarters();

            return View(model);
        }
        public ActionResult AddDepartment()
        {
            ScheduleManager manager = new ScheduleManager();

            var model = new DepartmentAddEditModel();
            ViewBag.QuarterList = manager.GetHPQuarterList();

            return View(model);
        }
        public ActionResult AddDisplayQuarter()
        {
            ScheduleManager manager = new ScheduleManager();

            QuarterItemModel newModel = new QuarterItemModel();
            ViewBag.QuarterList = manager.GetHPQuarterList();

            return PartialView("_AddDisplayQuarter", newModel);
        }
        public JsonResult AddInclusiveMiscSortToDepartment(DepartmentMiscSortItem entity)
        {
            ScheduleManager manager = new ScheduleManager();

            if (manager.AddNewMiscSortCodeInclude(entity))
            {

            return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false });
            }
        }
        public JsonResult AddDisplayQuarter(QuarterItemModel entity)
        {
            ScheduleManager manager = new ScheduleManager();

            if (manager.AddNewDisplayQuarter(entity))
            {

                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false });
            }
        }
        public ActionResult Departments(string id)
        {
            ScheduleManager manager = new ScheduleManager();

            //need to have a "Get YRQ from Url Name method)

            QuarterItemModel quarter = manager.GetQuarterItemFromUrlName(id);

            ViewBag.YearQuarterID = quarter.UrlName;
            ViewBag.YearQuarterDisplay = quarter.Title;
            var model = manager.GetDepartments(quarter.YearQuarterID,false);

            return View(model);
        }
        public ActionResult AddDepartment(DepartmentAddEditModel entity)
        {
            ScheduleManager manager = new ScheduleManager();

            if (manager.AddNewDepartment(entity))
            {
                return RedirectToAction("ManageDepartments");
            }
            else
            {
                var model = entity;
                return View(model);
            }
        }
        public ActionResult Department(string quarter, string department)
        {
            ScheduleManager manager = new ScheduleManager();
            QuarterItemModel currquarter = manager.GetQuarterItemFromUrlName(quarter);

            SearchModel search = manager.GetNewSearchModel(currquarter.YearQuarterID);
            search.DepartmentName = department;
            ViewBag.QuarterUrl = quarter;
            ViewBag.YearQuarterID = quarter;
            ViewBag.YearQuarterDisplay = currquarter.Title;
            ViewBag.YearQuarterCode = currquarter.YearQuarterID;
            var model = manager.GetSingleDepartment(search);

            return View(model);
        }
        public ActionResult CulturalDiversity(string id)
        {
            ScheduleManager manager = new ScheduleManager();
            QuarterItemModel currquarter = manager.GetQuarterItemFromUrlName(id);
            SearchModel search = manager.GetNewSearchModel(currquarter.YearQuarterID);
            search.CulturalDiversityOnly = true;
            ViewBag.QuarterUrl = id;
            ViewBag.YearQuarterID = currquarter.UrlName;
            ViewBag.YearQuarterDisplay = currquarter.Title;
            ViewBag.YearQuarterCode = currquarter.YearQuarterID;

            var model = manager.SearchCourses(search);

            return View(model);
        }
        public ActionResult RemoveDepartmentPrefix(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetDepartmentPrefixItem(id);

            return View(model);
        }
        public ActionResult ManageDepartments()
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetManageDepartmentList();

            return View(model);
        }
        public ActionResult LoadQuarterList()
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetAvailableQuarters();

            return PartialView("_DisplayQuarterList",model);
        }
        public ActionResult LoadPrefixListForDepartment(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetDepartmentEditPrefixes(id);

            return PartialView("_DepartmentPrefixList", model);
        }
        public ActionResult Search(string id)
        {
            ScheduleManager manager = new ScheduleManager();

            QuarterItemModel quarterItem = manager.GetQuarterItemFromUrlName(id);
            SearchModel search = manager.GetNewSearchModel(quarterItem.YearQuarterID);
            search.IncludeCanceledClasses = true;
            ViewBag.YearQuarterID = quarterItem.UrlName;
            ViewBag.QuarterUrl = quarterItem.UrlName;
            ViewBag.YearQuarterDisplay = quarterItem.Title;
            ViewBag.QuarterLink = quarterItem.UrlName;
            return View(search);
        }
        public ActionResult RemoveMiscSortValue(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetMiscSortItem(id);

            return View(model);
        }
        public ActionResult RemoveDisplayQuarter(QuarterItemModel entity)
        {
            ScheduleManager manager = new ScheduleManager();

            if (manager.RemoveDisplayQuarter(entity.DisplayQuarterID))
            {
                return RedirectToAction("ManageQuarters");
            }
            else
            {
                var model = manager.GetQuarterItemFromId(entity.DisplayQuarterID);
                return View(model);
            }
        }
        public JsonResult AddPrefixToDepartment(DepartmentPrefixItem entity)
        {
            ScheduleManager manager = new ScheduleManager();

            if (manager.AddPrefixToDepartment(entity))
            {
                return Json(new { success = true });
            }
            else
            {
                return Json(new { success = false });
            }
        }
        public ActionResult AddPrefixToDepartment(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            ViewBag.PrefixList = manager.GetDepartmentPrefixesFromHP();
            var model = new DepartmentPrefixItem();
            model.DepartmentId = id;

            return PartialView("_AddPrefixToDepartment", model);
        }
        public ActionResult Search(SearchModel searchOptions)
        {
            ScheduleManager manager = new ScheduleManager();

            ViewBag.YearQuarterCode = searchOptions.YearQuarterID;
            searchOptions.IncludeCanceledClasses = true;
            var yrqItem  = manager.GetQuarterItemFromYRQ(searchOptions.YearQuarterID);
            ViewBag.YearQuarterID = yrqItem.UrlName;
            var model = manager.GetSearchResults(searchOptions);

            return PartialView("_SearchResults", model);
        }
        public ActionResult RemoveDepartmentPrefix(DepartmentPrefixItem entity)
        {
            int deptId = entity.DepartmentId;

            ScheduleManager manager = new ScheduleManager();

            if (manager.RemoveDepartmentPrefixEntry(entity.PrefixId))
            {
                return RedirectToAction("EditDepartment", new { id = deptId });
            }
            else
            {
                return View("RemoveDepartmentPrefix", entity);
            }
        }
        public ActionResult RemoveDisplayQuarter(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetQuarterItemFromId(id);

            return View(model);
        }
        public ActionResult EditDepartment(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetDepartmentForEdit(id);
            ViewBag.QuarterList = manager.GetHPQuarterList();
            model.Prefixes = manager.GetDepartmentEditPrefixes(id);
            model.MiscSortToExclude = manager.GetDepartmentMiscSortCodesToExcludeForEdit(id);
            model.MiscSortToInclude = manager.GetDepartmentMiscSortCodesToIncludeForEdit(id);
            return View(model);
        }
        public ActionResult Index()
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetAvailableQuarters();

            if (model.Count > 1)
            {
                return View(model);
            }
            else
            {
                var available = model.First<QuarterItemModel>();
                return RedirectToAction("Search", new { id = available.UrlName });
            }
        }
        public ActionResult GetSectionStatus(string itemNumber, string yrq)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = new ClassStatusModel();

            var sectMod = manager.GetSectionInformation(itemNumber, yrq);

            //start

            string ayr = manager.GetAcademicYear(yrq);
            string sess = manager.GetQuarterSession(yrq);

            WTSClass post = new WTSClass();
            post.Url = "https://transact.edcc.edu/cgi-bin/rq230.exe";
            post.PostItems.Add("item", itemNumber);
            post.PostItems.Add("returnurl", "");
            post.PostItems.Add("request", "classchd");
            post.PostItems.Add("ayr", ayr);
            post.PostItems.Add("sess", sess);
            post.Type = WTSClass.PostTypeEnum.Post;
            string result = post.Post();
            DateTime processTime = DateTime.Now;
            HttpStatusCode statusCode = post.StatusCode;

            string classStatus = "";
            if (statusCode == HttpStatusCode.OK && result.IndexOf("EDMONDS COMMUNITY COLLEGE") != -1)
            {
                string courseId;
                string sectionNumber;

                int courseIdHeaderIndex = result.IndexOf("Course Id");
                int couseIdTextIndex = result.IndexOf(": ", courseIdHeaderIndex) + 2;

                StringBuilder builder = new StringBuilder();

                for (int i = couseIdTextIndex; result[i] != ' '; i++)
                {
                    builder.Append(result[i]);
                }
                courseId = builder.ToString();
                builder.Length = 0;

                int sectionNumberHeaderIndex = result.IndexOf("Sect", couseIdTextIndex);
                int sectionNumberTextIndex = result.IndexOf(": ", sectionNumberHeaderIndex) + 2;

                for (int i = sectionNumberTextIndex; result[i] != '<'; i++)
                {
                    builder.Append(result[i]);
                }
                sectionNumber = builder.ToString();
                builder.Length = 0;

                int statusHeaderIndex = result.IndexOf("Class Status", sectionNumberTextIndex);
                int statusTextIndex = result.IndexOf(": ", statusHeaderIndex) + 2;

                for (int i = statusTextIndex; result[i] != ' '; i++)
                {
                    builder.Append(result[i]);
                }
                classStatus = builder.ToString();

                if (classStatus == "OPEN")
                {
                    string openSeats;

                    int openSeatsHeaderIndex = result.IndexOf("Seats Available", statusTextIndex);
                    int openSeatsTextIndex = result.IndexOf(": ", openSeatsHeaderIndex) + 2;

                    builder.Length = 0;
                    for (int i = openSeatsTextIndex; result[i] != '<'; i++)
                    {
                        builder.Append(result[i]);
                    }
                    openSeats = builder.ToString();
                    model.CurrentStatus = "Open";
                    //lblStatus.CssClass = "ClassStatusOpen";
                    model.ClassOpen = true;
                    model.OpenSeats = (int.Parse(openSeats)).ToString();

                    model.ServerDown = false;
                }
                else
                {

                    model.CurrentStatus = "Closed";
                    model.ClassOpen = false;
                    model.ServerDown = false;
                }

                model.CourseID = courseId;
                model.Section = sectionNumber;
                model.StatusDateTime = processTime.ToString("G");
                model.ServerDown = false;
            }
            else
            {
                //
                //the server is down oh no!
                model.ServerDown = true;
            }
            //end

            model.CourseID = sectMod.CourseID;
            model.CourseTitle = sectMod.CourseTitle;
            model.AllowOnlineReg = sectMod.OnlineRegistration;
            model.ItemNumber = sectMod.ItemNumber;

            //Added waitlist info to status popup.  5/15/13  Robert.Pan
            //NOTE: This code gets built into ClassSchedule.dll
            string szWaitListCount = "0", szWaitListCapacity = "0";

            //Remove conditional as of 6/5/13 as requested.  Robert.Pan
            //if ((classStatus.ToUpper() != "OPEN") && (classStatus != ""))
            //{
                string dbConnectionString = "Server=odie; Database=Student; Trusted_Connection=True;";
                string szClassID = itemNumber + yrq;

                SqlConnection myConnection = new SqlConnection(dbConnectionString);
                myConnection.Open();
                SqlCommand cmd = new SqlCommand("StudentWaitlistCount_sp", myConnection);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter ClassID = cmd.Parameters.Add("@ClassID", SqlDbType.NVarChar);
                ClassID.Direction = ParameterDirection.Input;
                ClassID.Value = szClassID;
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                if (dr.Read())
                {
                    szWaitListCount = dr["WaitListCount"].ToString();
                    szWaitListCapacity = dr["WaitListCapacity"].ToString();
                }
                myConnection.Close();   //Not needed because of CommandBehavior.CloseConnection - just being paranoid.

                model.debug = szClassID;
            //}
            model.WaitListCount = szWaitListCount;
            model.WaitListCapacity = szWaitListCapacity;
            //End added waitlist info.

            return PartialView("_SectionStatusView", model);
        }
        public ActionResult RemoveMiscSortValue(DepartmentMiscSortItem entity)
        {
            int deptId = entity.DepartmentId;

            ScheduleManager manager = new ScheduleManager();

            if (manager.RemoveMiscSortCodeEntry(entity.MiscSortId))
            {
                return RedirectToAction("EditDepartment", new { id = deptId });
            }
            else
            {
                return View("RemoveMiscSortValue", entity);
            }
        }
        public FileStreamResult PrintSchedule(SearchModel searchOptions)
        {
            ScheduleManager manager = new ScheduleManager();

            ViewBag.YearQuarterCode = searchOptions.YearQuarterID;
            searchOptions.IncludeCanceledClasses = false;
            var yrqItem = manager.GetQuarterItemFromYRQ(searchOptions.YearQuarterID);
            ViewBag.YearQuarterID = yrqItem.UrlName;
            var model = manager.GetSearchResults(searchOptions);

            string tempResults = manager.GetXMLResults(model, searchOptions.FullDownLoad);

            byte[] byteArray = Encoding.ASCII.GetBytes(tempResults);
            MemoryStream stream = new MemoryStream(byteArray);

            FileStreamResult result = new FileStreamResult(stream, "text/xml");
            result.FileDownloadName = "classschedule.xml";
            return result;
        }
        public ActionResult GenerateXML(SearchModel searchOptions)
        {
            ScheduleManager manager = new ScheduleManager();

            ViewBag.YearQuarterCode = searchOptions.YearQuarterID;
            var yrqItem = manager.GetQuarterItemFromYRQ(searchOptions.YearQuarterID);
            ViewBag.YearQuarterID = yrqItem.UrlName;
            var model = manager.GetSearchResults(searchOptions);

            return PartialView("_SearchResults", model);
        }
        public JsonResult GetInstructorList(string id, string yrq)
        {
            ScheduleManager manager = new ScheduleManager();

            var instructorList = manager.GetInstructorList(id, yrq);

            var myData = instructorList.Select(a => new SelectListItem()
            {
                Text = a.DisplayName,
                Value = a.InstructorName,
            });

            return Json(myData, JsonRequestBehavior.AllowGet);
        }
        public ActionResult LoadMiscSortIncludeList(int id)
        {
            ScheduleManager manager = new ScheduleManager();

            var model = manager.GetDepartmentMiscSortCodesToIncludeForEdit(id);

            return PartialView("_DepartmentMiscSortIncludeList", model);
        }
        public ActionResult GenerateXML(string id)
        {
            ScheduleManager manager = new ScheduleManager();

            QuarterItemModel quarterItem = manager.GetQuarterItemFromUrlName(id);
            SearchModel search = manager.GetNewSearchModel(quarterItem.YearQuarterID);
            ViewBag.YearQuarterID = quarterItem.UrlName;
            ViewBag.QuarterUrl = quarterItem.UrlName;
            ViewBag.YearQuarterDisplay = quarterItem.Title;
            return View(search);
        }