Exemple #1
0
        private int priority = 0; // 0-1 small, 2-3 medium, 4-5 high

        public bool LoadCourseById(CrousesDBContext db, int id)
        {
            if (db.Courses.Any(x => x.ID == id))
            {
                var course = db.Courses.Where(x => x.ID == id).FirstOrDefault();
                this.ID                = course.ID;
                this.courseCode        = course.courseCode;
                this.courseName        = course.courseName;
                this.courseCategory    = course.courseCategory;
                this.courseDescription = course.courseDescription;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SetStudentCourses(TakenCoursesDBContext db, CrousesDBContext coursesDb)
        {
            if (db.TakenCourses.Any(x => x.studentId == this.id))
            {
                List <Courses>     coursesTaken = new List <Courses>();
                List <TakenCourse> courses;
                courses = db.TakenCourses.Where(x => x.studentId == this.id).ToList();
                for (int i = 0; i < courses.Count; i++)
                {
                    Courses course = new Courses();
                    if (course.LoadCourseById(coursesDb, courses[i].courseId))
                    {
                        coursesTaken.Add(course);
                    }
                }


                for (int i = 0; i < coursesTaken.Count; i++)
                {
                    switch (coursesTaken[i].courseCategory)
                    {
                    case "Elective":
                    {
                        electiveCoursesTaken.Add(coursesTaken[i]);
                        break;
                    }

                    case "Required":
                    {
                        requiredCoursesTaken.Add(coursesTaken[i]);
                        break;
                    }

                    case "GenEd":
                    {
                        regularCoursesTaken.Add(coursesTaken[i]);
                        break;
                    }
                    }
                }
            }
            else
            {
            }
        }
        public List <Courses> SetCoursePriority(CrousesDBContext db)
        {
            List <Courses> courses         = db.Courses.ToList();
            List <Courses> notTakenCourses = new List <Courses>();

            for (int i = 0; i < courses.Count; i++)
            {
                if (HasNotTakenCourse(courses[i]))
                {
                    notTakenCourses.Add(courses[i]);
                }
            }

            double electiveProgress = electiveCoursesTaken.Count / 6.0;
            double requiredProgress = requiredCoursesTaken.Count / 6.0;
            double genEdProgress    = regularCoursesTaken.Count / 6.0;

            if (Math.Min(electiveProgress, Math.Min(requiredProgress, genEdProgress)) == electiveProgress)
            {
                foreach (Courses course in notTakenCourses)
                {
                    if (course.courseCategory == "Elective")
                    {
                        course.SetPriority(3);
                    }
                    if (requiredProgress < genEdProgress)
                    {
                        if (course.courseCategory == "Required")
                        {
                            course.SetPriority(2);
                        }
                        else if (course.courseCategory == "GenEd")
                        {
                            course.SetPriority(1);
                        }
                    }
                    else
                    {
                        if (course.courseCategory == "Required")
                        {
                            course.SetPriority(1);
                        }
                        else if (course.courseCategory == "GenEd")
                        {
                            course.SetPriority(2);
                        }
                    }
                }
            }
            else if (Math.Min(electiveProgress, Math.Min(requiredProgress, genEdProgress)) == requiredProgress)
            {
                foreach (Courses course in notTakenCourses)
                {
                    if (course.courseCategory == "Required")
                    {
                        course.SetPriority(3);
                    }
                    if (electiveProgress < genEdProgress)
                    {
                        if (course.courseCategory == "Elective")
                        {
                            course.SetPriority(2);
                        }
                        else if (course.courseCategory == "GenEd")
                        {
                            course.SetPriority(1);
                        }
                    }
                    else
                    {
                        if (course.courseCategory == "Elective")
                        {
                            course.SetPriority(1);
                        }
                        else if (course.courseCategory == "GenEd")
                        {
                            course.SetPriority(2);
                        }
                    }
                }
            }
            else
            {
                foreach (Courses course in notTakenCourses)
                {
                    if (course.courseCategory == "GenEd")
                    {
                        course.SetPriority(3);
                    }
                    if (requiredProgress < electiveProgress)
                    {
                        if (course.courseCategory == "Required")
                        {
                            course.SetPriority(2);
                        }
                        else if (course.courseCategory == "Elective")
                        {
                            course.SetPriority(1);
                        }
                    }
                    else
                    {
                        if (course.courseCategory == "Required")
                        {
                            course.SetPriority(1);
                        }
                        else if (course.courseCategory == "Elective")
                        {
                            course.SetPriority(2);
                        }
                    }
                }
            }
            return(notTakenCourses);
        }