/// <summary> /// A function that returns information about a course given /// the course and user IDs /// </summary> public CourseViewModel GetCoursesById(int courseID, string userID) { var course = db.Courses.SingleOrDefault(x => x.ID == courseID); if (course == null) { return(null); } AssignmentsService tmp = new AssignmentsService(); List <AssignmentViewModel> assignentViewModel = tmp.GetAssignmentsInCourse(courseID); var coursesAsTeacher = GetCoursesWhereTeacher(userID); var coursesAsStudent = GetCoursesWhereStudent(userID); var students = GetAllStudents(courseID); var teachers = GetAllTeachers(courseID); string userName = (from u in db.Users where u.Id == userID select u.FullName).SingleOrDefault().ToString(); CourseViewModel viewModel = new CourseViewModel { Name = course.Name, ID = course.ID, UserID = userID, UserName = userName, Teachers = teachers, Students = students, Year = course.Year, Semester = course.Semester, CoursesAsStudent = coursesAsStudent, CoursesAsTeacher = coursesAsTeacher, Assignments = assignentViewModel, isTeacher = false, }; return(viewModel); }
/// <summary> /// A function that returns a list of assignmentviewmodels /// given a specific user ID /// </summary> public List <AssignmentViewModel> GetAllUserAssignments(string userID) { CourseService temp = new CourseService(); var allStudentCourses = temp.GetCoursesWhereStudent(userID); var allTeacherCourses = temp.GetCoursesWhereTeacher(userID); List <AssignmentViewModel> allAssignments = new List <AssignmentViewModel>(); AssignmentsService tmp = new AssignmentsService(); foreach (var item in allStudentCourses) { allAssignments.AddRange(tmp.GetAssignmentsInCourse(item.ID)); } foreach (var item in allTeacherCourses) { var teacherAssignments = tmp.GetAssignmentsInCourse(item.ID); foreach (var entry in teacherAssignments) { entry.IsTeacher = true; } allAssignments.AddRange(teacherAssignments); } return(allAssignments); }