示例#1
0
        /// <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);
        }
示例#2
0
        /// <summary>
        /// A function that returns a courseoverviewmodel containing
        /// all courses for a user and information about them
        /// </summary>
        public CourseOverViewModel GetAllInfo(string userID)
        {
            string              strID     = (from u in db.Users where u.Id == userID select u.Id).SingleOrDefault().ToString();
            AssignmentsService  tmp       = new AssignmentsService();
            CourseOverViewModel viewModel = new CourseOverViewModel
            {
                Name         = (from u in db.Users where u.Id == userID select u.FullName).SingleOrDefault().ToString(),
                UserID       = userID,
                whereTeacher = GetCoursesWhereTeacher(userID),
                whereStudent = GetCoursesWhereStudent(userID),
                assignments  = tmp.GetAllUserAssignments(userID)
            };

            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);
        }