コード例 #1
0
        /// <summary>
        /// Function to grab details of the signle course whose ID is provided by Student
        /// </summary>
        /// <param name="id"></param>
        /// <returns> details of a single course</returns>

        public Course GetCourseDetailsByID(string id) // Passing Course ID
        {
            ValidationException exception = new ValidationException();
            Course courseDetail           = null;
            int    parsedId;
            int    userId = int.Parse(User.Identity.Name);

            id = !string.IsNullOrWhiteSpace(id) ? id.Trim() : null;

            // check if id is non integer
            if (!int.TryParse(id, out parsedId))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid ID : course details not available, please go back to Main dashboard and try again"));
            }
            else
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    // To confirm that student do no access any other students course
                    // Select CourseID FROM student WHERE CourseID = -1 AND UserID = 6
                    Student confirmStudent = context.Students.Where(x => x.CourseID == parsedId && x.UserID == userId).SingleOrDefault();

                    if (confirmStudent != null)
                    {
                        courseDetail = context.Courses.Where(x => x.ID == parsedId).SingleOrDefault();
                    }
                    else
                    {
                        exception.ValidationExceptions.Add(new Exception("Invalid operation : you are not enrolled in this course"));
                    }
                }
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }

            return(courseDetail);
        }
コード例 #2
0
        public IActionResult CourseCreate(string instructor, string courseName, string subject, string courseDescription, string gradeLevel, DateTime?startDate, DateTime?endDate, int currentCapacity, int maxCapacity)
        {
            ViewBag.UserInformation = SharedFunctionsController.GetUserNameBySignInID(User.Identity.Name);
            using (LearningManagementContext context = new LearningManagementContext())
            {
                // Create a list based on first name and last name from the User table that has a role equal to 2 (which is "Instructor")
                var instructors = new SelectList(context.Users.Where(x => x.Role == 2)
                                                 .OrderBy(y => y.LastName)
                                                 .ToDictionary(us => us.ID, us => us.FirstName + " " + us.LastName), "Key", "Value", instructor);
                ViewBag.Instructors = instructors;
                ViewBag.CourseName  = courseName;

                // Create list of Subjects
                var courseSubjects = new List <string>()
                {
                    "English", "Math", "Science", "Social Studies"
                };
                // Populate dropdown list for subjects.
                var courseSubjectsList = new SelectList(courseSubjects.ToDictionary(s => s, s => s), "Key", "Value", courseSubjects);
                ViewBag.CourseSubjects = courseSubjectsList;

                ViewBag.Subject           = subject;
                ViewBag.StartDate         = startDate;
                ViewBag.EndDate           = endDate;
                ViewBag.CourseDescription = courseDescription;

                // Create list of GradeLevels
                var gradeLevels = new List <string>()
                {
                    "Kindergarten", "Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5", "Grade 6", "Grade 7", "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12"
                };
                // Populate dropdown list for grade levels.
                var gradeLevelList = new SelectList(gradeLevels.ToDictionary(g => g, g => g), "Key", "Value", gradeLevel);
                ViewBag.GradeLevels = gradeLevelList;

                ViewBag.GradeLevel  = gradeLevel;
                ViewBag.MaxCapacity = maxCapacity;
            }
            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            ViewBag.UserInformation = SharedFunctionsController.GetUserNameBySignInID(User.Identity.Name);
            using (LearningManagementContext context = new LearningManagementContext())
            {
                var course = await context.Courses.FindAsync(id);

                try
                {
                    if (course.StartDate < DateTime.Today)
                    {
                        exception.ValidationExceptions.Add(new Exception("Error: Cannot delete a course that is in progress."));
                    }

                    else if (course.EndDate > DateTime.Today && course.StartDate < DateTime.Today)
                    {
                        exception.ValidationExceptions.Add(new Exception("Error: Cannot delete a course that is in progress."));
                    }

                    if (exception.ValidationExceptions.Count > 0)
                    {
                        throw exception;
                    }
                    context.Courses.Remove(course);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(CourseList)));
                }

                catch (ValidationException e)
                {
                    ViewBag.Message   = "There exist problem(s) with your submission, see below.";
                    ViewBag.Exception = e;
                    ViewBag.Error     = true;
                }
                return(View(course));
            }
        }
コード例 #4
0
        /* ------------------------------------------Data -----------------------------------------------------*/
        /// <summary>
        /// This function grabs course List for individual instructor
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns>List of courses</returns>
        public List <Course> GetCourseByInstructorID(string UserId)
        {
            ValidationException exception          = new ValidationException();
            List <Course>       instructorsCourses = null;

            if (UserId != null)
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    instructorsCourses = context.Courses.Where(x => x.UserID == int.Parse(UserId)).OrderBy(x => x.Subject).ToList();
                }
            }
            else
            {
                exception.ValidationExceptions.Add(new Exception("If You Are experiencing trouble accessing your courses , Go back to main Instructor Dsahboard and select course again"));
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }
            return(instructorsCourses);
        }
コード例 #5
0
        public async Task <IActionResult> CourseDelete(int?id)
        {
            ViewBag.UserInformation = SharedFunctionsController.GetUserNameBySignInID(User.Identity.Name);
            using (LearningManagementContext context = new LearningManagementContext())
            {
                if (id == null)
                {
                    return(NotFound());
                }

                var course = await context.Courses
                             .FirstOrDefaultAsync(m => m.ID == id);

                if (course == null)
                {
                    ViewBag.CourseExists = false;
                    return(View());
                }

                ViewBag.CourseExists = true;
                return(View(course));
            }
        }
コード例 #6
0
        /* This file contains list of functions that are resued in more than one controller*/

        /// <summary>
        /// Function to get the information about user using their Signed in user ID
        /// </summary>
        /// <param name="userID"></param>
        /// <returns>All user information</returns>
        public static User GetUserNameBySignInID(string userID)
        {
            ValidationException exception = new ValidationException();
            User user = null;

            if (int.TryParse(userID, out int parsedId))
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    user = context.Users.Where(x => x.ID == parsedId).SingleOrDefault();
                }
            }
            else
            {
                exception.ValidationExceptions.Add(new Exception("We encountered a problem , Please logout and try again "));
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }

            return(user);
        }
コード例 #7
0
        /// <summary>
        /// Uses LINQ queiries to aet a list of courses that a given student, based on the students user id, is enrolled in
        /// </summary>
        /// <param name="userID"></param>
        /// <returns>A list of enrolled courses per given student</returns>
        public List <Course> GetEnrolledCoursesByStudentID(int userID)
        {
            List <Course>  enrolledCourses;
            List <Student> studentCourses;

            using (LearningManagementContext context = new LearningManagementContext())
            {
                studentCourses = context.Students.Where(x => x.UserID == userID).ToList();

                // Find unique list of course IDs that the student is enrolled in.
                List <int> courseIDs = new List <int>();
                foreach (Student student in studentCourses)
                {
                    if (!courseIDs.Contains(student.CourseID))
                    {
                        courseIDs.Add(student.CourseID);
                    }
                }

                // Get all additional course info that the student is enrolled in.
                enrolledCourses = context.Courses.Where(x => courseIDs.Contains(x.ID)).Include(x => x.User).OrderBy(x => x.Subject).ToList();
                return(enrolledCourses);
            }
        }
コード例 #8
0
        /// <summary>
        /// Function to enter the Answer of an assignment in the database by Student
        /// </summary>
        /// <param name="id"></param>
        /// <param name="answer"></param>
        /// <param name="courseID"></param>
        public void SubmitAssignment(string id, string answer, string courseID)
        {
            ValidationException exception = new ValidationException();
            bool flag = false;
            int  parsedId;

            // Trim the values
            id       = id?.Trim();
            answer   = answer?.Trim();
            courseID = courseID?.Trim();

            // Validation for  Assignment ID
            if (id == null || courseID == null)
            {
                exception.ValidationExceptions.Add(new Exception("ID not found, Go back to details page and try again"));
                flag = true;
            }
            else
            {
                if (!int.TryParse(id, out parsedId))
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid Course ID : Go back to main instructor dsahboard and select course again"));
                    flag = true;
                }
            }

            // Validation for answer
            if (answer == null)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid Value : Answer Required"));
                flag = true;
            }
            else
            {
                if (answer.Length > 2000)
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid value : cannot exceed character count of 2000, please rephrase"));
                    flag = true;
                }
            }


            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }


            if (flag == false)
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    // Add Values in assignment Table if all validations are passed
                    context.Submissions.Add(new Submit()
                    {
                        AssignmentID  = int.Parse(id),
                        StudentID     = GetStudentId(courseID, User.Identity.Name),
                        DateSubmitted = DateTime.Now,
                        Answer        = answer
                    });
                    context.SaveChanges();
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Function to update the Score and remarks in submit, table these fields are added by instructor
        /// </summary>
        /// <param name="submitId"></param>
        /// <param name="remarks"></param>
        /// <param name="scoreObtained"></param>
        /// <param name="totalScore"></param>
        public void SubmitAssignmentScoreAndRemarks(string submitId, string remarks, string scoreObtained, string totalScore)
        {
            ValidationException exception = new ValidationException();
            Submit updateSubmission       = null;

            submitId      = submitId?.Trim();
            remarks       = remarks?.Trim();
            scoreObtained = scoreObtained?.Trim();
            totalScore    = totalScore?.Trim();

            bool flag = false;

            int parsedId;
            int parsedScoreObtained;
            int parsedTotalScore;

            // Validation for submitID
            if (!int.TryParse(submitId, out parsedId))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid submission ID : go back to course list and try again"));
                flag = true;
            }

            // Validation for Total Score
            if (!int.TryParse(totalScore, out parsedTotalScore))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value: total score required"));
                flag = true;
            }


            // Validation for remarks
            if (remarks != null)
            {
                if (remarks.Length > 500)
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid value : cannot exceed character count of 500, please rephrase"));
                    flag = true;
                }
            }

            // Validation for Score obtained
            if (!int.TryParse(scoreObtained, out parsedScoreObtained))
            {
                exception.ValidationExceptions.Add(new Exception("Invalud value : numeric Value required for score obtained"));
                flag = true;
            }
            else
            {
                if (!((parsedScoreObtained > -1) && (parsedScoreObtained < parsedTotalScore + 1)))
                {
                    exception.ValidationExceptions.Add(new Exception($"Invalid value : enter total score between 0 and {parsedTotalScore}"));
                    flag = true;
                }
            }


            if (flag == false)
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    updateSubmission = context.Submissions.Where(x => x.ID == int.Parse(submitId)).SingleOrDefault();
                    updateSubmission.ScoreObtained = int.Parse(scoreObtained);
                    updateSubmission.Remarks       = remarks;
                    context.SaveChanges();
                }
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }
        }
コード例 #10
0
        /// <summary>
        /// Function to insert assignment values by instructor into assignment table
        /// Validation # 1 : Due Date for assignment Cannot be before Course start date
        /// Validation # 2 : Due date for assignment cannot be set before today
        /// Validation # 3 : Due date cannot be after Course end date
        /// </summary>
        /// <param name="question"></param>
        /// <param name="dueDate"></param>
        /// <param name="totalScore"></param>
        /// <param name="id"></param>
        public void CreateNewAssignment(string question, string dueDate, string totalScore, string id)
        {
            ValidationException exception = new ValidationException();

            // Trim the values
            question   = question?.Trim();
            dueDate    = dueDate?.Trim();
            totalScore = totalScore?.Trim();
            id         = id?.Trim();

            bool flag = false;

            int parsedId;
            int parsedTotalScore;

            // Validation for courseID
            if (id == null)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid ID : Go back to details page and try again"));
                flag = true;
            }
            else
            {
                if (!int.TryParse(id, out parsedId))
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid Course ID : Go back to main Instructor Dsahboard and select course again"));
                    flag = true;
                }
            }

            // Validation for question
            if (question == null)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid Value : Question Required"));
                flag = true;
            }
            else
            {
                if (question.Length > 500)
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid character count : cannot exceed 500 characters, please rephrase"));
                    flag = true;
                }
            }

            // Validation for dueDate
            if (dueDate == null)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid Date : Due Date Required"));
                flag = true;
            }
            else
            {
                if (DateTime.Parse(dueDate) < DateTime.Now)
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid Date : Due Date Can not be set prior to today"));
                    flag = true;
                }
            }

            // Validation for TotalScore
            if (totalScore == null)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid Score : total score for assignment required"));
                flag = true;
            }
            else
            {
                if (!int.TryParse(totalScore, out parsedTotalScore))
                {
                    exception.ValidationExceptions.Add(new Exception("Invalid Value : Numeric Value required for total score"));
                    flag = true;
                }
                else
                {
                    if (!((parsedTotalScore > -1) && (parsedTotalScore < 101)))
                    {
                        exception.ValidationExceptions.Add(new Exception("Invalid value : enter total score between 0 and 100"));
                        flag = true;
                    }
                }
            }


            if (flag == false)
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    Course course = GetCourseDetailsByID(id);

                    if (DateTime.Parse(dueDate) < course.StartDate)
                    {
                        exception.ValidationExceptions.Add(new Exception("Invalid Due date : due date for an assignment cannot be before course start date"));
                        flag = true;
                    }
                    else
                    if (DateTime.Parse(dueDate) > course.EndDate)
                    {
                        exception.ValidationExceptions.Add(new Exception($"Invalid Due date : due date for an assignment cannot be later than course end date {course.EndDate}"));
                        flag = true;
                    }


                    if (flag == false)
                    {
                        // Add Values in assignment Table if all validations are passed
                        context.Assignments.Add(new Assignment()
                        {
                            CourseID   = int.Parse(id),
                            Question   = question,
                            DueDate    = DateTime.Parse(dueDate),
                            TotalScore = int.Parse(totalScore)
                        });
                        context.SaveChanges();
                    }
                }
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }
        }
コード例 #11
0
        /* ----------------------------------------------- Data ------------------------------------------*/
        /// <summary>
        /// Function To add Validated user credentials in User database
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="role"></param>
        public void Register(string firstName, string lastName, string email, string password, string role)
        {
            ValidationException exception = new ValidationException();

            // Trim the values
            firstName = firstName?.Trim();
            lastName  = lastName?.Trim();
            email     = email?.Trim();
            password  = password?.Trim();
            role      = role?.Trim();
            bool flag = false;

            // Validation for First Name
            if (string.IsNullOrWhiteSpace(firstName))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : First Name Not Provided"));
                flag = true;
            }
            else if (firstName.Length > 50)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : First Name Cannot exceed 50 characters"));
                flag = true;
            }

            // Validation for Last Name
            if (string.IsNullOrWhiteSpace(lastName))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Last Name Not Provided"));
                flag = true;
            }
            else if (lastName.Length > 50)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Last Name Cannot exceed 50 characters"));
                flag = true;
            }

            // Validation for Email
            if (string.IsNullOrWhiteSpace(email))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Email Not Provided"));
                flag = true;
            }
            else if (email.Length > 50)
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Email Cannot exceed 50 characters"));
                flag = true;
            }
            else if (!Regex.IsMatch(email, @"^[\w-!$*%^\.]+@([\w-]+\.)+[\w-]{2,4}$"))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Incorrect Email Address  "));
                flag = true;
            }

            // Validation for Password
            if (string.IsNullOrWhiteSpace(password))
            {
                exception.ValidationExceptions.Add(new Exception("Invalid value : Password Not Provided"));
                flag = true;
            }
            else if (password.Length > 50)
            {
                exception.ValidationExceptions.Add(new Exception(" Invalid value : Password Cannot exceed 50 characters"));
                flag = true;
            }

            if (string.IsNullOrWhiteSpace(role))
            {
                exception.ValidationExceptions.Add(new Exception("Please Select a Role"));
                flag = true;
            }


            if (flag == false)
            {
                using (LearningManagementContext context = new LearningManagementContext())
                {
                    // Checking for Email duplication
                    if ((context.Users.Where(x => (x.EMail.Trim().ToUpper()) == email.ToUpper()).Count()) > 0)
                    {
                        exception.ValidationExceptions.Add(new Exception("Email already exist, Try again with a new one"));
                        flag = true;
                    }

                    if (flag == false)
                    {
                        // Add Values in user Table if all validations are passed
                        context.Users.Add(new User()
                        {
                            FirstName = firstName,
                            LastName  = lastName,
                            EMail     = email.ToUpper(),
                            Password  = SignInController.HashAndSaltPassowrd(password, email.ToUpper()),
                            Role      = int.Parse(role),
                            JoinDate  = DateTime.Now
                        });
                        context.SaveChanges();
                    }
                }
            }

            if (exception.ValidationExceptions.Count > 0)
            {
                throw exception;
            }
        }
コード例 #12
0
        public async Task <IActionResult> CourseEdit(int id, [Bind("ID,UserID,CourseName,Subject,CourseDescription,GradeLevel,StartDate,EndDate,CurrentCapacity,MaxCapacity")] Course course)
        {
            ViewBag.UserInformation = SharedFunctionsController.GetUserNameBySignInID(User.Identity.Name);
            course.CourseName       = course.CourseName != null?course.CourseName.Trim() : null;

            course.Subject = course.Subject != null?course.Subject.Trim() : null;

            course.CourseDescription = course.CourseDescription != null?course.CourseDescription.Trim() : null;

            using (LearningManagementContext context = new LearningManagementContext())
            {
                if (id != course.ID)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        if (course.MaxCapacity <= 0)
                        {
                            exception.ValidationExceptions.Add(new Exception("Invalid Maximum Capacity: Course must have a minimum of 1 student."));
                        }
                        else
                        {
                            if (course.CurrentCapacity > course.MaxCapacity)
                            {
                                exception.ValidationExceptions.Add(new Exception("Invalid Current Capacity: Current capacity cannot exceed maximum capacity."));
                            }
                            else
                            {
                                if (course.StartDate > course.EndDate)
                                {
                                    exception.ValidationExceptions.Add(new Exception("Invalid Start Date: Course start date cannot be after end date."));
                                }
                            }
                        }

                        if (exception.ValidationExceptions.Count > 0)
                        {
                            throw exception;
                        }

                        ViewBag.CourseExists = true;

                        context.Update(course);
                        await context.SaveChangesAsync();

                        ViewBag.Message = $"Successfully updated course!";
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!(context.Courses.Any(x => x.ID == id)))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw exception;
                        }
                    }
                    catch (ValidationException e)
                    {
                        ViewBag.Message   = "There is an issue(s) with the submission, please see the following details:";
                        ViewBag.Exception = e;
                        ViewBag.Error     = true;
                    }

                    // Create a list based on first name and last name from the User table that has a role equal to 2 (which is "Instructor")
                    var instructors = new SelectList(context.Users.Where(x => x.Role == 2)
                                                     .OrderBy(y => y.LastName)
                                                     .ToDictionary(us => us.ID, us => us.FirstName + " " + us.LastName), "Key", "Value", course.UserID);
                    ViewBag.Instructors       = instructors;
                    ViewBag.CourseName        = course.CourseName;
                    ViewBag.Subject           = course.Subject;
                    ViewBag.StartDate         = course.StartDate;
                    ViewBag.EndDate           = course.EndDate;
                    ViewBag.CourseDescription = course.CourseDescription;

                    // Create list of GradeLevels
                    var gradeLevels = new List <string>()
                    {
                        "Kindergarten", "Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5", "Grade 6", "Grade 7", "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12"
                    };
                    // Populate dropdown list for grade levels.
                    var gradeLevelList = new SelectList(gradeLevels.ToDictionary(g => g, g => g), "Key", "Value", course.GradeLevel);
                    ViewBag.GradeLevels = gradeLevelList;

                    ViewBag.GradeLevel      = course.GradeLevel;
                    ViewBag.CurrentCapacity = course.CurrentCapacity;
                    ViewBag.MaxCapacity     = course.MaxCapacity;
                }
            }
            return(View());
        }
コード例 #13
0
        public async Task <IActionResult> CourseCreate(string instructor, string courseName, string subject, string courseDescription, string gradeLevel, DateTime?startDate, DateTime?endDate, int currentCapacity, int maxCapacity, [Bind("ID,UserID,CourseName,Subject,CourseDescription,GradeLevel,StartDate,EndDate,MaxCapacity")] Course course)
        {
            ViewBag.UserInformation = SharedFunctionsController.GetUserNameBySignInID(User.Identity.Name);
            using (LearningManagementContext context = new LearningManagementContext())
            {
                instructor = instructor != null?instructor.Trim() : null;

                courseName = courseName != null?courseName.Trim() : null;

                subject = subject != null?subject.Trim() : null;

                courseDescription = courseDescription != null?courseDescription.Trim() : null;

                if (ModelState.IsValid)
                {
                    try
                    {
                        if (course.MaxCapacity <= 0)
                        {
                            exception.ValidationExceptions.Add(new Exception("Invalid Maximum Capacity: Course must have a minimum of 1 student"));
                        }
                        else
                        {
                            if (course.CurrentCapacity > course.MaxCapacity)
                            {
                                exception.ValidationExceptions.Add(new Exception("Invalid Current Capacity: Current capacity cannot exceed maximum capacity"));
                            }
                            else
                            {
                                if (course.StartDate > course.EndDate)
                                {
                                    exception.ValidationExceptions.Add(new Exception("Invalid Start Date: Course start date cannot be set past the end date"));
                                }

                                else
                                {
                                    if (course.StartDate < DateTime.Today)
                                    {
                                        exception.ValidationExceptions.Add(new Exception("Invalid Start Date: Course start date cannot be set prior to todays date"));
                                    }

                                    else
                                    {
                                        if (course.EndDate < DateTime.Today)
                                        {
                                            exception.ValidationExceptions.Add(new Exception("Invalid End Date: Course end date cannot be set prior to todays date"));
                                        }

                                        else
                                        {
                                            if (context.Courses.Any(x => x.CourseName == course.CourseName))
                                            {
                                                exception.ValidationExceptions.Add(new Exception("Invalid Course Name: That course already exists"));
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (exception.ValidationExceptions.Count > 0)
                        {
                            throw exception;
                        }
                        context.Add(course);
                        await context.SaveChangesAsync();

                        ViewBag.Message = $"Successfully created course!";
                    }
                    catch (ValidationException e)
                    {
                        ViewBag.Message   = "There is an issue(s) with the submission, please see the following details:";
                        ViewBag.Exception = e;
                        ViewBag.Error     = true;
                    }

                    var instructors = new SelectList(context.Users.Where(x => x.Role == 2)
                                                     .OrderBy(y => y.LastName)
                                                     .ToDictionary(us => us.ID, us => us.FirstName + " " + us.LastName), "Key", "Value", instructor);
                    ViewBag.Instructors = instructors;
                    ViewBag.CourseName  = courseName;

                    // Create list of Subjects
                    var courseSubjects = new List <string>()
                    {
                        "English", "Math", "Science", "Social Studies"
                    };
                    // Populate dropdown list for subjects.
                    var courseSubjectsList = new SelectList(courseSubjects.ToDictionary(s => s, s => s), "Key", "Value", courseSubjects);
                    ViewBag.CourseSubjects = courseSubjectsList;

                    ViewBag.Subject           = subject;
                    ViewBag.StartDate         = startDate;
                    ViewBag.EndDate           = endDate;
                    ViewBag.CourseDescription = courseDescription;

                    // Create list of GradeLevels
                    var gradeLevels = new List <string>()
                    {
                        "Kindergarten", "Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5", "Grade 6", "Grade 7", "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12"
                    };
                    // Populate dropdown list for grade levels.
                    var gradeLevelList = new SelectList(gradeLevels.ToDictionary(g => g, g => g), "Key", "Value", gradeLevel);
                    ViewBag.GradeLevels = gradeLevelList;

                    ViewBag.GradeLevel = gradeLevel;
                    //ViewBag.CurrentCapacity = currentCapacity;
                    ViewBag.MaxCapacity = maxCapacity;
                }
            }
            return(View(course));
        }