// GET: Section public IActionResult Index() { User currentUser = SessionVariables.GetCurrentUser(HttpContext); if (currentUser != null && currentUser.Role != null && currentUser.Role.Sections.CanView) { 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); } } List <Section> sections = DAL.GetSectionsByAcademicSemesterID(SessionVariables.GetSessionAcademicSemester(HttpContext).ID); 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; return(View(sections)); } else { SessionVariables.SetErrorMessage("Login required"); return(RedirectToAction("Login", "User")); } }
public IActionResult Create([Bind("ID,Name,DepartmentComments,Notes,RequiresPermission,RequiresMoodle,CRN,DateArchived,DateCreated,StudentLimit," + "StartTime,EndTime,PartOfTermID,CourseID,PrimaryInstructorPercent,SecondaryInstructorPercent,ScheduleTypeID,Number" + "PrimaryInstructorID,SecondaryInstructorID,RoomID")] Section section) { if (ModelState.IsValid) { //section number isn't being passed from the form for some reason so it's being grabbed directly from the form section.Number = Request.Form["Number"]; section.AcademicSemesterID = SessionVariables.GetSessionAcademicSemester(HttpContext).ID; if (section.PrimaryInstructorID > 0 && section.SecondaryInstructorID > 0) { if (section.PrimaryInstructorPercent + section.SecondaryInstructorPercent != 100) { ModelState.AddModelError("PrimaryInstructorPercent", "Percentages don't equal 100%"); ModelState.AddModelError("SecondaryInstructorPercent", "Percentages don't equal 100%"); SetUpSectionViewBags(section, true); return(View(section)); } } else { section.PrimaryInstructorPercent = 100; } section.ID = DAL.AddSection(section); if (section.ID > 0) { SessionVariables.SetSuccessMessage("Section created"); if (section.Course.CrossListedCourseID > 0) { CreateCrossListedSection(ref section); } SetUpSectionDays(section); SetUpSectionInstructors(section); ChangeLog changeLog = new ChangeLog(); changeLog.SectionID = section.ID; changeLog.DateCreated = DateTime.Now; changeLog.DateDeleted = DAL.MaximumDateTime; changeLog.DateImported = DAL.MinimumDateTime; DAL.AddChangeLog(changeLog); } else { SessionVariables.SetErrorMessage("Section create failed"); } return(RedirectToAction(nameof(Index))); } SetUpSectionViewBags(section); return(View(section)); }
// 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")); } }
public IActionResult Edit(int id, [Bind("ID,Number,DepartmentComments,Notes,RequiresPermission,RequiresMoodle,CRN,DateArchived,DateCreated,StudentLimit," + "StartTime,EndTime,PartOfTermID,CourseID,CRN,PrimaryInstructorPercent,SecondaryInstructorPercent,CrossScheduledSectionID," + "ScheduleTypeID,PrimaryInstructorID,FeeID,AcademicSemesterID,SecondaryInstructorID,RoomID")] Section section) { if (id != section.ID) { return(NotFound()); } if (section.XListID == null) { section.XListID = ""; } Section oldSection = DAL.GetSection((int)id); List <Day> days = oldSection.Days; if (ModelState.IsValid) { section.AcademicSemesterID = SessionVariables.GetSessionAcademicSemester(HttpContext).ID; if (section.PrimaryInstructorID > 0 && section.SecondaryInstructorID > 0) { if (section.PrimaryInstructorPercent + section.SecondaryInstructorPercent != 100) { ModelState.AddModelError("PrimaryInstructorPercent", "Percentages don't equal 100%"); ModelState.AddModelError("SecondaryInstructorPercent", "Percentages don't equal 100%"); SetUpSectionViewBags(section, true); User currentUser = SessionVariables.GetCurrentUser(HttpContext); if (currentUser != null && currentUser.Role != null) { ViewData["CanDelete"] = currentUser.Role.Sections.CanDelete; } else { ViewData["CanDelete"] = false; } return(View(section)); } } else { section.PrimaryInstructorPercent = 100; } SetUpSectionDays(section); SetUpSectionInstructors(section); UpdateChangeLog(oldSection, section); if (section.CrossListedSectionID > 0) { UpdateCrossListedSection(ref section); } int updatedSuccessfully = DAL.UpdateSection(section); if (updatedSuccessfully > 0) { SessionVariables.SetSuccessMessage("Section edited"); } else { SessionVariables.SetErrorMessage("Section edit failed"); } return(RedirectToAction(nameof(Index))); } SetUpSectionViewBags(section, true); return(View(section)); }
private void SetUpSectionViewBags(Section section, bool withValues = false) { List <Room> rooms = DAL.GetRooms(); rooms.Add(new Room { ID = -1, Number = 0, Building = new Building { ID = -1, Name = "None", Campus = new Campus { ID = -1, Name = "" } } }); List <Instructor> instructors = DAL.GetInstructors(); section.GetInstructorDetails(); List <Course> courses = DAL.GetCourses(); List <Department> departments = DAL.GetDepartments(); instructors.Add(new Instructor { ID = -1, FirstName = "None", MiddleName = "", LastName = "" }); List <Day> days = DAL.GetDays(); Dictionary <int, bool> dictDays = new Dictionary <int, bool>(); foreach (Day day in days) { if (!dictDays.ContainsKey(day.ID)) { dictDays.Add(day.ID, false); } } if (withValues) { ViewData["DepartmentID"] = new SelectList(departments, "ID", "Abbreviation", section.Course.DepartmentID); ViewData["PartOfTermID"] = new SelectList(DAL.GetPartOfTerms(), "ID", "Name", section.PartOfTermID); ViewData["RoomID"] = new SelectList(rooms, "ID", "NameAndCampus", section.RoomID); ViewData["ScheduleTypeID"] = new SelectList(DAL.GetScheduleTypes(), "ID", "Name", section.ScheduleTypeID); ViewData["PrimaryInstructorID"] = new SelectList(instructors, "ID", "FullName", section.PrimaryInstructorID); ViewData["SecondaryInstructorID"] = new SelectList(instructors, "ID", "FullName", section.SecondaryInstructorID); ViewData["SemesterID"] = new SelectList(DAL.GetSemesters(), "ID", "Name", section.AcademicSemester.SemesterID); ViewData["CourseNumbers"] = new SelectList(courses, "ID", "NumberAndTitle", section.CourseID); foreach (Day day in section.Days) { if (dictDays.ContainsKey(day.ID)) { dictDays[day.ID] = true; } } } else { ViewData["DepartmentID"] = new SelectList(departments, "ID", "Abbreviation"); ViewData["PartOfTermID"] = new SelectList(DAL.GetPartOfTerms(), "ID", "Name"); ViewData["RoomID"] = new SelectList(DAL.GetRooms(), "ID", "NameAndCampus"); ViewData["ScheduleTypeID"] = new SelectList(DAL.GetScheduleTypes(), "ID", "Name"); ViewData["PrimaryInstructorID"] = new SelectList(instructors, "ID", "FullName", -1); ViewData["SecondaryInstructorID"] = new SelectList(instructors, "ID", "FullName", -1); ViewData["SemesterID"] = new SelectList(DAL.GetSemesters(), "ID", "Name"); ViewData["CourseNumbers"] = new SelectList(courses, "ID", "NumberAndTitle"); } ViewData["AcademicSemester"] = SessionVariables.GetSessionAcademicSemester(HttpContext).Display; ViewData["AllDays"] = days; ViewData["Days"] = dictDays; }