Ejemplo n.º 1
0
        public ActionResult Attendance()
        {
            var userId = User.Identity.GetUserId();

            if (userId == null || userId == "")
            {
                return(View());
            }

            var student  = _studentDataService.GetByUserId(userId);
            var group    = _groupDataService.GetByStudent(student.Id);
            var lectures = _lectureDataService.GetByGroupId(group.Id);

            var attendanceStats = new List <StudentAttendanceViewModel>();

            var generalStats = new StudentAttendanceViewModel
            {
                Subject               = "General",
                LectureCount          = _getOccurencesCount(lectures),
                AttendedLecturesCount = _getAttendedLecturesCount(lectures, student)
            };

            attendanceStats.Add(generalStats);

            foreach (var lecture in lectures)
            {
                var attended = _attendanceDataService.GetStudentAttendance(student.Id, lecture.Id);

                if (attendanceStats.Any(x => x.Subject == lecture.Subject.Name))
                {
                    attendanceStats.FirstOrDefault(x => x.Subject == lecture.Subject.Name).LectureCount          += lecture.Occurences.Count;
                    attendanceStats.FirstOrDefault(x => x.Subject == lecture.Subject.Name).AttendedLecturesCount +=
                        attended.AttendedLectures == "" ? 0 : attended.AttendedLectures.Split(',').Count();
                }
                else
                {
                    var stats = new StudentAttendanceViewModel
                    {
                        Subject               = lecture.Subject.Name,
                        LectureCount          = lecture.Occurences.Count,
                        AttendedLecturesCount = attended.AttendedLectures == "" ? 0 : attended.AttendedLectures.Split(',').Count()
                    };
                    attendanceStats.Add(stats);
                }
            }

            return(View(attendanceStats));
        }