Example #1
0
        // GET: Section/Edit/5
        public IActionResult Edit(int?id)
        {
            Section section     = null;
            User    currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Sections.CanEdit)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                section = DAL.GetSection((int)id);
                if (section == null)
                {
                    return(NotFound());
                }
                SetUpSectionViewBags(section, true);
                if (currentUser != null && currentUser.Role != null)
                {
                    ViewData["CanDelete"] = currentUser.Role.Sections.CanDelete;
                }
                else
                {
                    ViewData["CanDelete"] = false;
                }
                return(View(section));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission edit sections");
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("FirstName,MiddleName,LastName,Number,CourseLoad,ID")] Instructor instructor)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanEdit)
            {
                if (id != instructor.ID)
                {
                    return(NotFound());
                }
                if (ModelState.IsValid)
                {
                    if (DAL.UpdateInstructor(instructor) > 0)
                    {
                        SessionVariables.SetSuccessMessage("Instructor edited successfully");
                    }
                    else
                    {
                        SessionVariables.SetErrorMessage("Instructor edit failed");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(instructor));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to edit instructors");
                return(RedirectToAction("Index"));
            }
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Name,IsAdmin,Buildings,Campuses,Courses,Days,Departments,DateTimeModels,Fees,Instructors," +
                                                       "Roles,Rooms,ScheduleTypes,Sections,Spreadsheets,Subjects,Users,ID")] Role role)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Roles.CanAdd)
            {
                if (ModelState.IsValid)
                {
                    if (DAL.AddRole(role) > 0)
                    {
                        SessionVariables.SetSuccessMessage("Role created successfully");
                    }
                    else
                    {
                        SessionVariables.SetErrorMessage("Role create failed");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(role));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to create roles");
                return(RedirectToAction("Index"));
            }
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("FirstName,MiddleName,LastName,Number,CourseLoad,ID")] Instructor instructor)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanAdd)
            {
                if (ModelState.IsValid)
                {
                    if (DAL.AddInstructor(instructor) > 0)
                    {
                        SessionVariables.SetSuccessMessage("Instructor created successfully");
                    }
                    else
                    {
                        SessionVariables.SetErrorMessage("Instructor create failed");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["InstructorID"] = new SelectList(DAL.GetInstructors(), "ID", "ID", instructor.ID);
                return(View(instructor));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to create instructors");
                return(RedirectToAction("Index"));
            }
        }
Example #5
0
        // 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"));
            }
        }
Example #6
0
        // GET: Instructor/Create
        public IActionResult Create()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanAdd)
            {
                return(View());
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to create instructors");
                return(RedirectToAction("Index"));
            }
        }
Example #7
0
        // GET: SpreadsheetVariables/Create
        public IActionResult Create()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Spreadsheets.CanAdd)
            {
                SpreadsheetVariables sv = new SpreadsheetVariables();
                return(View(sv));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to create spreadsheet details");
                return(RedirectToAction("Index"));
            }
        }
Example #8
0
        // GET: SpreadsheetVariables
        public IActionResult Index()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Spreadsheets.CanEdit)
            {
                List <SpreadsheetVariables> spreadsheetVariables = DAL.GetSpreadsheetVariablesList();
                return(RedirectToAction("Edit", spreadsheetVariables[0]));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to edit spreadsheet details");
                return(RedirectToAction("Index", "Section"));
            }
        }
Example #9
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Spreadsheets.CanDelete)
            {
                DAL.RemoveSpreadsheetVariables((int)id);
                return(RedirectToAction("Index"));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete spreadsheet details");
                return(RedirectToAction("Index"));
            }
        }
Example #10
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.ScheduleTypes.CanDelete)
            {
                DAL.RemoveScheduleType(id);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete schedule types");
                return(RedirectToAction("Index"));
            }
        }
Example #11
0
        // GET: Role/Create
        public IActionResult Create()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Roles.CanAdd)
            {
                ViewData["RoleID"] = new SelectList(DAL.GetRoles(), "ID", "Name");
                return(View());
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to create roles");
                return(RedirectToAction("Index"));
            }
        }
Example #12
0
        // GET: Role
        public async Task <IActionResult> Index()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Roles.CanView)
            {
                List <Role> roles = DAL.GetRoles();
                return(View(roles));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to view roles");
                return(RedirectToAction("Index", "Section"));
            }
        }
Example #13
0
        public IActionResult DeleteConfirmed(int id, [Bind("ID,Number,DepartmentComments,Notes,RequiresPermission,RequiresMoodle,CRN,DateArchived,DateCreated,StudentLimit," +
                                                           "StartTime,EndTime,PartOfTermID,CourseID,ScheduleTypeID,PrimaryInstructorID,SectionFeeID,SecondaryInstructorID,RoomID,")] Section section)
        {
            Section sectionToDelete = DAL.GetSection(id);
            User    currentUser     = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Sections.CanDelete)
            {
                ChangeLog changeLog = DAL.GetChangeLogBySection(sectionToDelete);
                //checks if the section was created after the spreadsheet import
                changeLog.DateDeleted       = DateTime.Now;
                sectionToDelete.DateDeleted = DateTime.Now;
                if (changeLog.DateCreated >= changeLog.DateImported)
                {
                    //completely delete the section so it isn't put on the spreadsheet as it was created after the import
                    List <InstructorToSection> instructorToSections = DAL.GetInstructorsBySectionID(id);
                    foreach (InstructorToSection its in instructorToSections)
                    {
                        DAL.RemoveInstructorToSection(its.ID);
                    }
                    List <SectionDay> sectionDays = DAL.GetSectionDaysBySectionID(id);
                    foreach (SectionDay sd in sectionDays)
                    {
                        DAL.RemoveSectionDay(sd.ID);
                    }
                    ChangeLog changeLogToDelete = DAL.GetChangeLogBySection(section);
                    DAL.RemoveChangeLog(changeLogToDelete);
                    DAL.RemoveSection(section);
                }
                int updatedChangelog = DAL.UpdateChangeLog(changeLog);
                int updatedSection   = DAL.UpdateSection(sectionToDelete);
                if (updatedChangelog >= 0 && updatedSection >= 0)
                {
                    SessionVariables.SetSuccessMessage("Section deleted");
                }
                else
                {
                    SessionVariables.SetErrorMessage("Section delete failed");
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete sections");
                return(RedirectToAction("Index"));
            }
        }
Example #14
0
        // 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"));
            }
        }
Example #15
0
        // GET: Section/Create
        public IActionResult Create()
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Sections.CanAdd)
            {
                Section newSection = new Section()
                {
                    CourseID = -1
                };
                ViewData["Section"] = newSection;
                SetUpSectionViewBags(newSection);
                return(View());
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to do that");
                return(RedirectToAction("index"));
            }
        }
Example #16
0
        // 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"));
            }
        }
Example #17
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanDelete)
            {
                if (DAL.RemoveInstructor(id) > 0)
                {
                    SessionVariables.SetSuccessMessage("Instructor deleted successfully");
                }
                else
                {
                    SessionVariables.SetErrorMessage("Instructor delete failed");
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete instructors");
                return(RedirectToAction("Index"));
            }
        }
Example #18
0
        // GET: Section/Delete/5
        public IActionResult Delete(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role.Sections.CanDelete)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                Section section = DAL.GetSection((int)id);
                if (section == null)
                {
                    return(NotFound());
                }
                return(View(section));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete sections");
                return(RedirectToAction("index"));
            }
        }
Example #19
0
        // GET: Instructor/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Instructors.CanView)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                Instructor instructor = DAL.GetInstructor((int)id);
                if (instructor == null)
                {
                    return(NotFound());
                }
                return(View(instructor));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to view instructors");
                return(RedirectToAction("Index", "Section"));
            }
        }
Example #20
0
        // GET: Role/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Roles.CanEdit)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                Role role = DAL.GetRole((int)id);
                if (role == null)
                {
                    return(NotFound());
                }
                return(View(role));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to edit roles");
                return(RedirectToAction("Index"));
            }
        }
Example #21
0
        // GET: ScheduleType/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.ScheduleTypes.CanDelete)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                ScheduleType scheduleType = DAL.GetScheduleType((int)id);
                if (scheduleType == null)
                {
                    return(NotFound());
                }
                return(View(scheduleType));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete schedule types");
                return(RedirectToAction("Index"));
            }
        }
Example #22
0
        // GET: SpreadsheetVariables/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            User currentUser = SessionVariables.GetCurrentUser(HttpContext);

            if (currentUser != null && currentUser.Role != null && currentUser.Role.Spreadsheets.CanDelete)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                SpreadsheetVariables spreadsheetVariables = DAL.GetSpreadsheetVariables((int)id);
                if (spreadsheetVariables == null)
                {
                    return(NotFound());
                }
                return(View(spreadsheetVariables));
            }
            else
            {
                SessionVariables.SetErrorMessage("You do not have permission to delete spreadsheet details");
                return(RedirectToAction("Index"));
            }
        }
Example #23
0
        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));
        }