예제 #1
0
        public ActionResult AddCourseVM(int? id)
        {
            Student student = db.Students.Find(id);
            List<Course> alreadyTaken = student.CoursesTaken.ToList();
            Concentration conc = db.Concentrations.Find(student.Concentration.ID);
            List<BaseCourse> potentialCourses = conc.RequiredCourses.ToList();
            AddCourseViewModel vModel = new AddCourseViewModel(student, potentialCourses);

            List<Course> listCourses = new List<Course>();

            foreach (BaseCourse baseC in potentialCourses)
            {
                Course c = new Course();
                c.BaseCourse = baseC;
                listCourses.Add(c);
            }

            foreach (Course c in alreadyTaken)
            {
                listCourses.RemoveAll(s => s.BaseCourse.ID == c.BaseCourseID);
            }

            vModel.PossibleCourses = listCourses;

            for (int i = 0; i < listCourses.Count; i++)
            {
                var selectList = new SelectList(db.Semesters, "Sname", "Sname", "1");
                this.ViewData[string.Format("PossibleCourses[{0}].Semester", i)] = selectList;

                List<SelectListItem> items = new List<SelectListItem>();
                items.Add(new SelectListItem { Text = "A", Value = "4" });
                items.Add(new SelectListItem { Text = "B", Value = "3" });
                items.Add(new SelectListItem { Text = "C", Value = "2" });
                items.Add(new SelectListItem { Text = "D", Value = "1" });
                items.Add(new SelectListItem { Text = "F", Value = "0" });
                this.ViewData[string.Format("PossibleCourses[{0}].Grade", i)] = items;
                this.ViewData[string.Format("selected[{0}]", i)] = 1;
            }

            return View("AddCourseVM", vModel);
        }
예제 #2
0
        public ActionResult RecommendCourses(int? id)
        {
            Student student = db.Students.Find(id);
            Concentration conc = student.Concentration;
            List<Course> possibleRecommendations = new List<Course>();
            foreach (BaseCourse b in conc.RequiredCourses)
            {
                Course c = new Course();
                c.BaseCourse = b;
                possibleRecommendations.Add(c);
            }

            ICollection<Course> recCollection = possibleRecommendations.Where(p => !student.CoursesTaken.Any(p2 => p2.BaseCourse.Name == p.BaseCourse.Name)).ToList();
            List<Course> toRemove = new List<Course>();

            foreach (Course c in recCollection)
            {
               bool hasIt = false;
               foreach (Course c2 in student.CoursesTaken)
               {
                   String pName = c2.BaseCourse.Department + c2.BaseCourse.CourseNumber;
                   foreach (Prerequisite p in c.BaseCourse.Prerequisites)
                   {
                       if (p.PrereqName == pName)
                       {
                           hasIt = true;
                       }
                   }
               }
                if (c.BaseCourse.Prerequisites.Count() == 0)
                {
                    hasIt = true;
                }

                if (!hasIt)
                {
                    toRemove.Add(c);
                }
            }

            foreach(Course c in toRemove)
            {
                recCollection.Remove(c);
            }

            student.CoursesRecommended = recCollection;

            db.Entry(student).State = EntityState.Modified;
            db.SaveChanges();

            return View("RecommendCourses", student);
        }