Exemplo n.º 1
0
 private void PopulateAssignedLecturerData(Course course)
 {
     var allLecturers = db.Lecturers;
     var courseLecturers = new HashSet<int>(course.AllLecturesTeachingTheCourse.Select(c => c.LecturerID));
     var viewModel = new List<AssignedLecturerData>();
     foreach (var lecturer in allLecturers)
     {
         viewModel.Add(new AssignedLecturerData
         {
             LecturerID = lecturer.LecturerID,
             FirstName = lecturer.FirstName,
             LastName = lecturer.LastName,
             Assigned = courseLecturers.Contains(lecturer.LecturerID)
         });
     }
     ViewBag.Lecturers = viewModel;
 }
Exemplo n.º 2
0
        private void UpdateCourseLecturers(string[] selectedLecturers, Course CourseToUpdate)
        {
            if (selectedLecturers == null)
            {
                CourseToUpdate.AllLecturesTeachingTheCourse = new List<Lecturer>();
                return;
            }

            var selectedLecturersHS = new HashSet<string>(selectedLecturers);
            var CourseLecturers = new HashSet<int>
                (CourseToUpdate.AllLecturesTeachingTheCourse.Select(c => c.LecturerID));
            foreach (var lecturer in db.Lecturers)
            {
                if (selectedLecturersHS.Contains(lecturer.LecturerID.ToString()))
                {
                    if (!CourseLecturers.Contains(lecturer.LecturerID))
                    {
                        CourseToUpdate.AllLecturesTeachingTheCourse.Add(lecturer);
                    }
                }
                else
                {
                    if (CourseLecturers.Contains(lecturer.LecturerID))
                    {
                        CourseToUpdate.AllLecturesTeachingTheCourse.Remove(lecturer);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public ActionResult CreateCourse()
 {
     var course = new Course();
     course.AllLecturesTeachingTheCourse = new List<Lecturer>();
     PopulateDepartmentsDropDownList();
     PopulateAssignedLecturerData(course);
     return View();
 }