Example #1
0
        public List <AssignmentsPerCoursePerStudent> AllAssignmentsPerAllCoursePerAllStudent()
        {
            List <Student>              students = GetAll();
            List <StudentCourse>        watches  = new StudentCourseService().GetAll();
            List <AssignmentsPerCourse> assignmentsPerCourses = new CourseService().AllAssignmentsPerAllCourses();
            var querySql = from s in students
                           join w in watches
                           on s.StudentId equals w.StudentId
                           join aPc in assignmentsPerCourses
                           on w.CourseId equals aPc.Course.CourseId
                           select new
            {
                Students             = s,
                AssignmentsPerCourse = aPc
            };
            var groupedByStudents = querySql.GroupBy(s => s.Students);
            List <AssignmentsPerCoursePerStudent> AllassignmentsPerAllStudentsPerAllCourses = new List <AssignmentsPerCoursePerStudent>();

            foreach (var group in groupedByStudents)
            {
                AssignmentsPerCoursePerStudent assignmentsPerStudentsPerCourse = new AssignmentsPerCoursePerStudent();
                assignmentsPerStudentsPerCourse.Student = group.Key;
                //assignmentsPerStudentsPerCourse.Student = group.Key;
                foreach (var item in group)
                {
                    //assignmentsPerStudentsPerCourse.Students.Add(item.Student);
                    assignmentsPerStudentsPerCourse.AssignmentsPerCourses.Add(item.AssignmentsPerCourse);
                }
                AllassignmentsPerAllStudentsPerAllCourses.Add(assignmentsPerStudentsPerCourse);
            }
            return(AllassignmentsPerAllStudentsPerAllCourses);
        }
        public List <StudentsPerCourse> AllStudentsPerAllCourses()
        {
            List <Course>        courses  = GetAll();
            List <Student>       students = new StudentService().GetAll();
            List <StudentCourse> watches  = new StudentCourseService().GetAll();

            var querySql = from s in students
                           join w in watches
                           on s.StudentId equals w.StudentId
                           join c in courses
                           on w.CourseId equals c.CourseId
                           select new
            {
                Student = s,
                Course  = c
            };
            List <StudentsPerCourse> allStudentsPerAllCourses = new List <StudentsPerCourse>();
            var groupedByCourses = querySql.GroupBy(g => g.Course);

            foreach (var group in groupedByCourses)
            {
                StudentsPerCourse studentsPerCourse = new StudentsPerCourse();
                studentsPerCourse.Course = group.Key;
                foreach (var item in group)
                {
                    studentsPerCourse.Students.Add(item.Student);
                }
                allStudentsPerAllCourses.Add(studentsPerCourse);
            }
            return(allStudentsPerAllCourses);
        }
Example #3
0
        public List <CoursesPerStudent> MultyCoursesPerSrudent()
        {
            List <Student>       students = GetAll();
            List <Course>        courses  = new CourseService().GetAll();
            List <StudentCourse> watches  = new StudentCourseService().GetAll();

            var querySql = from s in students
                           join w in watches
                           on s.StudentId equals w.StudentId
                           join w1 in watches
                           on w.StudentId equals w1.StudentId
                           join c in courses
                           on w.CourseId equals c.CourseId
                           where w.CourseId != w1.CourseId
                           select new
            {
                Student = s,
                Course  = c
            };

            List <CoursesPerStudent> MultyCoursesPerSrudent = new List <CoursesPerStudent>();
            var groupedByStudents = querySql.GroupBy(s => s.Student);

            foreach (var group in groupedByStudents)
            {
                CoursesPerStudent coursesPerStudent = new CoursesPerStudent();
                coursesPerStudent.Student = group.Key;
                foreach (var item in group.Distinct())
                {
                    //count++;
                    coursesPerStudent.Courses.Add(item.Course);
                }

                MultyCoursesPerSrudent.Add(coursesPerStudent);
            }
            return(MultyCoursesPerSrudent);
        }