Beispiel #1
0
        /// <summary>
        ///     Apply a course to a requirement set for a user
        /// </summary>
        /// <param name="username">Username of user to move course for</param>
        /// <param name="course">CourseModel for course to move</param>
        /// <param name="requirementSet">RequirementSetModel to move course into</param>
        /// <returns>Success status of move</returns>
        public static bool ApplyCourse(string username, CourseModel course, RequirementSetModel requirementSet)
        {
            using (var entities = GetEntityModel())
            {
                var user = entities.ApplicationUsers.FirstOrDefault(appuser => appuser.Username == username);
                if (user == null) return false;

                var report = user.CAPPReports.FirstOrDefault();
                if (report == null) return false;

                var dbset = report.RequirementSets.FirstOrDefault(set => set.Name == requirementSet.Name);
                if (dbset == null) return false;

                var newCourse =
                    entities.Courses.FirstOrDefault(c => c.CommunicationIntensive == course.CommIntensive &&
                                                         c.Credits == course.Credits &&
                                                         c.Department == course.DepartmentCode &&
                                                         Math.Abs(c.Grade - course.Grade) < 0.01 &&
                                                         c.Number == course.CourseNumber &&
                                                         c.PassNC == course.PassNoCredit &&
                                                         c.Semester == course.Semester &&
                                                         c.RequirementSet.CAPPReport.ApplicationUser
                                                             .Username == username);
                if (newCourse == null) return false;

                newCourse.RequirementSet = dbset;
                entities.SaveChanges();
                return true;
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Adds a new course to the Unapplied Courses RequirementSet for a specified user
        /// </summary>
        /// <param name="username">Username for user to add new course for</param>
        /// <param name="newCourse">CourseModel containing information about the new course</param>
        /// <param name="requirementSetName">Name of the requirement set to retrieve</param>
        /// <returns>Success state of the course addition</returns>
        public static bool AddNewCourse(string username, CourseModel newCourse, string requirementSetName)
        {
            using (var entities = GetEntityModel())
            {
                var user = entities.ApplicationUsers.FirstOrDefault(appuser => appuser.Username == username);
                if (user == null) return false;

                var report = user.CAPPReports.FirstOrDefault();
                if (report == null) return false;

                var reqSet = report.RequirementSets.FirstOrDefault(set => set.Name == requirementSetName);
                if (reqSet == null) return false;

                reqSet.Courses.Add(new Course
                {
                    Credits = newCourse.Credits,
                    Department = newCourse.DepartmentCode,
                    Grade = newCourse.Grade,
                    Number = newCourse.CourseNumber,
                    PassNC = newCourse.PassNoCredit,
                    Semester = newCourse.Semester,
                    CommunicationIntensive = newCourse.CommIntensive
                });
                entities.SaveChanges();
                return true;
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Remove a course for a specified user
        /// </summary>
        /// <param name="username">Username of user to remove course for</param>
        /// <param name="oldCourse">CourseModel containing information about course to remove</param>
        /// <returns>Success state of course removal</returns>
        public static bool RemoveCourse(string username, CourseModel oldCourse)
        {
            using (var entities = GetEntityModel())
            {
                var user = entities.ApplicationUsers.FirstOrDefault(appuser => appuser.Username == username);
                if (user == null) return false;

                var report = user.CAPPReports.FirstOrDefault();
                if (report == null) return false;

                var reqset =
                    report.RequirementSets.FirstOrDefault(set => set.Name == oldCourse.RequirementSetName);
                if (reqset == null) return false;

                var courseToRemove =
                    reqset.Courses.FirstOrDefault(course => course.Department == oldCourse.DepartmentCode &&
                                                            course.Number == oldCourse.CourseNumber &&
                                                            Math.Abs(course.Grade - oldCourse.Grade) < 0.01 &&
                                                            course.Credits == oldCourse.Credits &&
                                                            course.Semester == oldCourse.Semester &&
                                                            course.PassNC == oldCourse.PassNoCredit &&
                                                            course.CommunicationIntensive == oldCourse.CommIntensive);
                if (courseToRemove == null) return false;

                entities.Courses.Remove(courseToRemove);
                entities.SaveChanges();
                return true;
            }
        }
Beispiel #4
0
 /// <summary>
 ///     Remove course from the database
 /// </summary>
 /// <param name="username">Username for user to remove course for</param>
 /// <param name="oldCourse">CourseModel conataining information about the course to remove</param>
 /// <returns>Success state of course removal</returns>
 public static bool RemoveCourse(string username, CourseModel oldCourse)
 {
     return EntitiesHelper.RemoveCourse(username, oldCourse);
 }
Beispiel #5
0
 /// <summary>
 ///     Apply a course to a requirement set for a user
 /// </summary>
 /// <param name="username">Username of user to move course for</param>
 /// <param name="course">CourseModel to move</param>
 /// <param name="requirementSet">RequirementSetModel to move course into</param>
 /// <returns>Success status of move</returns>
 public static bool ApplyCourse(string username, CourseModel course, RequirementSetModel requirementSet)
 {
     return requirementSet.CanApplyCourse(course) && EntitiesHelper.ApplyCourse(username, course, requirementSet);
 }
Beispiel #6
0
 /// <summary>
 ///     Add a new course for the user
 /// </summary>
 /// <param name="username">Username for user to add new course for</param>
 /// <param name="newCourse">CourseModel contianing new course information</param>
 /// <param name="requirementSetName">Name of the requirement set to get</param>
 /// <returns>Success state of the course addition</returns>
 public static bool AddNewCourse(string username, CourseModel newCourse,
     string requirementSetName = "Unapplied Courses")
 {
     return EntitiesHelper.AddNewCourse(username, newCourse, requirementSetName);
 }