// GET: Instructor public async Task <IActionResult> Index() { User currentUser = SessionVariables.GetCurrentUser(HttpContext); if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanView) { List <Instructor> instructors = DAL.GetInstructors(); Dictionary <int, List <Section> > instructorSchedules = new Dictionary <int, List <Section> >(); List <InstructorToSection> instructorSections = DAL.GetInstructorToSectionsByAcademicSemesterID(SessionVariables.GetSessionAcademicSemesterID(HttpContext)); List <Section> sections = DAL.GetSectionsByAcademicSemesterID(SessionVariables.GetSessionAcademicSemesterID(HttpContext)); foreach (Instructor instructor in instructors) { if (!instructorSchedules.ContainsKey(instructor.ID)) { instructorSchedules.Add(instructor.ID, new List <Section>()); } foreach (InstructorToSection its in instructorSections) { if (its.InstructorID == instructor.ID) { instructorSchedules[instructor.ID].Add(DAL.GetSection(its.SectionID)); } } } List <AcademicSemester> academicSemesters = DAL.GetAcademicSemesters(); List <int> years = new List <int>(); foreach (AcademicSemester academicSemester in academicSemesters) { if (!years.Contains(academicSemester.AcademicYear)) { years.Add(academicSemester.AcademicYear); } } ViewData["AcademicSemesterYear"] = SessionVariables.GetSessionAcademicSemester(HttpContext).AcademicYear; ViewData["SemesterID"] = new SelectList(DAL.GetSemesters(), "ID", "Name", SessionVariables.GetSessionAcademicSemester(HttpContext).SemesterID); ViewData["AcademicYears"] = new SelectList(years, SessionVariables.GetSessionAcademicSemester(HttpContext).AcademicYear); ViewData["AcademicSemester"] = SessionVariables.GetSessionAcademicSemester(HttpContext).Display; ViewData["InstructorSections"] = instructorSchedules; return(View(instructors)); } else { SessionVariables.SetErrorMessage("You do not have permission to view instructors"); return(RedirectToAction("Index", "Section")); } }
// GET: InstructorToSection public async Task <IActionResult> Index() { User currentUser = SessionVariables.GetCurrentUser(HttpContext); if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanView && currentUser.Role.Sections.CanView) { Dictionary <int, Section> sections = DAL.GetSectionsByAcademicSemesterID(SessionVariables.GetSessionAcademicSemesterID(HttpContext)).ToDictionary(x => x.ID, x => x); List <InstructorToSection> instructorToSections = DAL.GetInstructorToSectionsByAcademicSemesterID(SessionVariables.GetSessionAcademicSemesterID(HttpContext)); foreach (InstructorToSection iToS in instructorToSections) { iToS.Section = sections[iToS.SectionID]; } return(View(instructorToSections)); } else { SessionVariables.SetErrorMessage("You do not have permission to view that"); return(RedirectToAction("Index", "Section")); } }