Esempio n. 1
0
        public async Task <AttendanceSummary> GetAttendanceSummary(int teacherId, GradingPeriod gradingPeriod)
        {
            var classes = ServiceLocator.ClassService.GetTeacherClasses(gradingPeriod.SchoolYearRef, teacherId, gradingPeriod.MarkingPeriodRef);

            if (classes.Count == 0)
            {
                return(new AttendanceSummary
                {
                    ClassesDaysStat = new List <ClassDailyAttendanceSummary>(),
                    Students = new List <StudentAttendanceSummary>()
                });
            }
            var classesIds                = classes.Select(x => x.Id).ToList();
            var attSummarytask            = ConnectorLocator.AttendanceConnector.GetSectionAttendanceSummary(classesIds, gradingPeriod.StartDate, gradingPeriod.EndDate);
            var students                  = ServiceLocator.StudentService.GetTeacherStudents(teacherId, gradingPeriod.SchoolYearRef);
            var sectionsAttendanceSummary = await attSummarytask;
            var res = new AttendanceSummary();
            var dailySectionAttendances = new List <DailySectionAbsenceSummary>();
            var studentAtts             = new List <StudentSectionAbsenceSummary>();
            var sectionStSet            = new HashSet <Pair <int, int> >();
            var sectionDaySet           = new HashSet <Pair <int, DateTime> >();

            foreach (var sectionAttendanceSummary in sectionsAttendanceSummary)
            {
                foreach (var dailySectionAtt in sectionAttendanceSummary.Days)
                {
                    var pair = new Pair <int, DateTime>(dailySectionAtt.SectionId, dailySectionAtt.Date);
                    if (!sectionDaySet.Contains(pair))
                    {
                        sectionDaySet.Add(pair);
                        dailySectionAttendances.Add(dailySectionAtt);
                    }
                }
                foreach (var student in sectionAttendanceSummary.Students)
                {
                    var pair = new Pair <int, int>(student.SectionId, student.StudentId);
                    if (!sectionStSet.Contains(pair))
                    {
                        sectionStSet.Add(pair);
                        studentAtts.Add(student);
                    }
                }
            }
            studentAtts         = studentAtts.Where(x => classesIds.Contains(x.SectionId)).ToList();
            res.ClassesDaysStat = ClassDailyAttendanceSummary.Create(dailySectionAttendances, classes);
            res.Students        = StudentAttendanceSummary.Create(studentAtts, students, classes);
            return(res);
        }
        public async Task <AttendanceSummary> GetAttendanceSummary(int teacherId, GradingPeriod gradingPeriod)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            var classes    = ServiceLocator.ClassService.GetTeacherClasses(gradingPeriod.SchoolYearRef, teacherId, gradingPeriod.MarkingPeriodRef);
            var classesIds = classes.Select(x => x.Id).ToList();
            var students   = ServiceLocator.StudentService.GetTeacherStudents(teacherId, Context.SchoolYearId.Value);
            var sectionsAttendanceSummary = GetSectionAttendanceSummary(classesIds, gradingPeriod.StartDate, gradingPeriod.EndDate);
            var res = new AttendanceSummary();
            var dailySectionAttendances = new List <DailySectionAbsenceSummary>();
            var studentAtts             = new List <StudentSectionAbsenceSummary>();

            foreach (var sectionAttendanceSummary in sectionsAttendanceSummary)
            {
                dailySectionAttendances.AddRange(sectionAttendanceSummary.Days);
                studentAtts.AddRange(sectionAttendanceSummary.Students);
            }
            res.ClassesDaysStat = ClassDailyAttendanceSummary.Create(dailySectionAttendances, classes);
            studentAtts         = studentAtts.Where(x => classesIds.Contains(x.SectionId)).ToList();
            res.Students        = StudentAttendanceSummary.Create(studentAtts, students, classes);
            return(res);
        }