Exemple #1
0
        public ActionResult StudentAttendance(int studentId, DateTime?date)
        {
            date = date ?? Context.NowSchoolTime;
            var attendanceReasons  = SchoolLocator.AttendanceReasonService.GetAll();
            var studentAttendances = SchoolLocator.AttendanceService.GetStudentAttendancesByDateRange(studentId, date.Value, date.Value).FirstOrDefault();

            return(Json(StudentDateAttendanceViewData.Create(studentAttendances, attendanceReasons), 6));
        }
Exemple #2
0
        public static AttendanceForStudentCalendarViewData Create(DateTime date, bool isCurrentMonth, int personId, IList <StudentDateAttendance> studentAttendances, IList <AttendanceReason> reasons)
        {
            var moreCount = 0;
            IList <AttendanceForStudentCalendarItemViewData> itemAttendances;
            var studentAttendance = studentAttendances.FirstOrDefault(att => att.Date == date);
            var attendances       = studentAttendance != null ? studentAttendance.StudentPeriodAttendances : new List <StudentPeriodAttendance>();
            var count             = attendances.Count(x => x.IsAbsentOrLate);
            var showGroupedData   = count > NON_PRESENT_COUNT;

            if (showGroupedData)
            {
                itemAttendances = attendances
                                  .GroupBy(x => x.Level)
                                  .ToDictionary(x => x.Key, x => x.ToList())
                                  .OrderByDescending(x => x.Value.Count)
                                  .Select(x => AttendanceForStudentCalendarItemViewData.Create(x.Value.First(), x.Value.Count))
                                  .ToList();
            }
            else
            {
                itemAttendances = attendances.Select(x => AttendanceForStudentCalendarItemViewData.Create(x, 1)).ToList();
            }

            if (itemAttendances.Count > ATTENDANCE_COUNT)
            {
                moreCount = showGroupedData
                                ? itemAttendances.Skip(ATTENDANCE_COUNT).Sum(x => x.Count)
                                : itemAttendances.Skip(ATTENDANCE_COUNT).Count();

                itemAttendances = itemAttendances.Take(ATTENDANCE_COUNT).ToList();
            }
            var res = new AttendanceForStudentCalendarViewData(date, isCurrentMonth)
            {
                IsAbsent        = studentAttendance != null && studentAttendance.IsAbsent,
                IsExcused       = studentAttendance != null && studentAttendance.IsExcused,
                Attendances     = itemAttendances,
                MoreCount       = moreCount,
                ShowGroupedData = showGroupedData,
            };

            if (studentAttendance != null)
            {
                res.StudentAttendance = StudentDateAttendanceViewData.Create(studentAttendance, reasons);
            }
            return(res);
        }