Esempio n. 1
0
        public async Task <ReportData> GetReportByStudent(StudentDto student, CourseDto course)
        {
            var reportHeader = new ReportHeader {
                Course = course.Name, Student = student.FullName, Lecture = null
            };

            IList <JournalRecordDto> journalRecords = await _journalService.GetRecords(0, student.Id, course.Id);

            IList <LectureDto> lectures = await _lectureService.GetAllByCourse(course.Id);

            ReportRecord[] reportRecords = journalRecords.Select(dto => new ReportRecord
            {
                Lecture    = lectures.First(lectureDto => lectureDto.Id == dto.LectureId).Name,
                Attendance = dto.Attendance,
                Score      = dto.Score,
                Student    = null
            }).ToArray();

            double?attendancePercentage = reportRecords.IsEmpty()
                ? null
                : reportRecords.Average(record => Convert.ToInt32(record.Attendance)) * 100;

            double?averageScore = reportRecords.IsEmpty()
                ? null
                : reportRecords.Average(record => record.Score);
            var report = new ReportData
            {
                Header  = reportHeader,
                Records = reportRecords,
                AttendancePercentage = attendancePercentage,
                AverageScore         = averageScore
            };

            return(report);
        }
Esempio n. 2
0
        public async Task <ActionResult <IList <LectureModel> > > GetAll(int courseId = default)
        {
            if (courseId < 0)
            {
                ModelState.AddModelError(nameof(courseId), "");
                return(BadRequest(ModelState));
            }

            try
            {
                IList <LectureDto> dtos = courseId == default
                    ? await _lectureService.GetAll()
                    : await _lectureService.GetAllByCourse(courseId);

                var models = _mapper.Map <LectureModel[]>(dtos);
                return(models);
            }
            catch (IncorrectIdException e)
            {
                _logger.LogWarning(e, "It seems, validation does not cover some errors.");
                return(BadRequest(e.Message));
            }
        }