Ejemplo n.º 1
0
 private void PopulateAssignedCourseData(School school)
 {
     var allCourses = db.Courses;
     var schoolCourses = new HashSet<int>(school.CoursesLearnedInSchool.Select(c => c.CourseID));
     var viewModel = new List<AssignedCourseData>();
     foreach (var course in allCourses)
     {
         viewModel.Add(new AssignedCourseData
         {
             CourseID = course.CourseID,
             Name = course.Name,
             Assigned = schoolCourses.Contains(course.CourseID)
         });
     }
     ViewBag.Courses = viewModel;
 }
Ejemplo n.º 2
0
        private void UpdateSchoolCourses(string[] selectedCourses, School SchoolToUpdate)
        {
            if (selectedCourses == null)
            {
                SchoolToUpdate.CoursesLearnedInSchool = new List<Course>();
                return;
            }

            var selectedCoursesHS = new HashSet<string>(selectedCourses);
            var schoolCourses = new HashSet<int>
                (SchoolToUpdate.CoursesLearnedInSchool.Select(c => c.CourseID));
            foreach (var course in db.Courses)
            {
                if (selectedCoursesHS.Contains(course.CourseID.ToString()))
                {
                    if (!schoolCourses.Contains(course.CourseID))
                    {
                        SchoolToUpdate.CoursesLearnedInSchool.Add(course);
                    }
                }
                else
                {
                    if (schoolCourses.Contains(course.CourseID))
                    {
                        SchoolToUpdate.CoursesLearnedInSchool.Remove(course);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public ActionResult CreateSchool()
 {
     var school = new School();
     school.CoursesLearnedInSchool = new List<Course>();
     PopulateAssignedCourseData(school);
     return View();
 }