コード例 #1
0
 /// <summary>
 /// creates new InstructorToSections if they don't exist for a given Section
 /// </summary>
 /// <param name="section"></param>
 private static void CreateNewInstructorToSections(Section section)
 {
     if (section.PrimaryInstructorID != -1)
     {
         InstructorToSection primaryInstructor = DAL.GetInstructorToSectionByInstructorIDAndSectionID(section.ID, section.PrimaryInstructorID);
         if (primaryInstructor == null)
         {
             InstructorToSection newInstructorToSection = new InstructorToSection();
             newInstructorToSection.SectionID          = section.ID;
             newInstructorToSection.InstructorID       = section.PrimaryInstructorID;
             newInstructorToSection.TeachingPercentage = section.PrimaryInstructorPercent;
             newInstructorToSection.IsPrimary          = true;
             DAL.AddInstructorToSection(newInstructorToSection);
             section.Instructors.Add(newInstructorToSection);
         }
     }
     if (section.SecondaryInstructorID != -1)
     {
         InstructorToSection secondaryInstructor = DAL.GetInstructorToSectionByInstructorIDAndSectionID(section.ID, section.SecondaryInstructorID);
         if (secondaryInstructor == null)
         {
             InstructorToSection newInstructorToSection = new InstructorToSection();
             newInstructorToSection.SectionID          = section.ID;
             newInstructorToSection.InstructorID       = section.SecondaryInstructorID;
             newInstructorToSection.TeachingPercentage = section.SecondaryInstructorPercent;
             newInstructorToSection.IsPrimary          = false;
             DAL.AddInstructorToSection(newInstructorToSection);
             section.Instructors.Add(newInstructorToSection);
         }
     }
 }
コード例 #2
0
 public async Task <IActionResult> Create([Bind("InstructorID,SectionID,IsPrimary,TeachingPercentage,ID")] InstructorToSection instructorToSection)
 {
     if (ModelState.IsValid)
     {
         DAL.AddInstructorToSection(instructorToSection);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["InstructorID"] = new SelectList(DAL.GetInstructors(), "ID", "FullName", instructorToSection.InstructorID);
     ViewData["SectionID"]    = new SelectList(DAL.GetSections(), "ID", "SectionNumberAndCourseName", instructorToSection.SectionID);
     return(View(instructorToSection));
 }
コード例 #3
0
        // GET: InstructorToSection/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            InstructorToSection instructorToSection = DAL.GetInstructorToSection((int)id);

            if (instructorToSection == null)
            {
                return(NotFound());
            }

            return(View(instructorToSection));
        }
コード例 #4
0
        // GET: InstructorToSection/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            InstructorToSection instructorToSection = DAL.GetInstructorToSection((int)id);

            if (instructorToSection == null)
            {
                return(NotFound());
            }
            ViewData["InstructorID"] = new SelectList(DAL.GetInstructors(), "ID", "FullName", instructorToSection.InstructorID);
            ViewData["SectionID"]    = new SelectList(DAL.GetSections(), "ID", "SectionNumberAndCourseName", instructorToSection.SectionID);

            return(View(instructorToSection));
        }
コード例 #5
0
        // GET: InstructorToSection/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanView && currentUser.Role.Sections.CanView)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                InstructorToSection instructorToSection = DAL.GetInstructorToSection((int)id);
                if (instructorToSection == null)
                {
                    return(NotFound());
                }
                return(View(instructorToSection));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to view that");
                return(RedirectToAction("Index", "Section"));
            }
        }