Exemple #1
0
        public async Task <Result <StudentsResultsDto> > GetStudentsResultAsync(StudentsRequestDto <StudentResultType> request)
        {
            var errors = ValidateStudentsRequest(request);

            if (errors.Any())
            {
                return(Result <StudentsResultsDto> .GetError(ErrorCode.ValidationError, string.Join(";\n", errors)));
            }

            var result           = new StudentsResultsDto();
            var studentGroupsIds = request.StudentGroupId.HasValue
                ? new List <long> {
                request.StudentGroupId.Value
            }
                : await _dashboardRepository
            .GetGroupsIdsByCourseIdAsync(request.CourseId.Value, request.StartDate, request.FinishDate);

            var studentsIds = await _dashboardRepository.GetStudentsIdsByGroupIdsAsync(studentGroupsIds);

            if (request.IncludeAnalytics.Contains(StudentResultType.AverageStudentMark))
            {
                result.AverageStudentsMarks = await _dashboardRepository
                                              .GetStudentAverageMarksByStudentIdsAndGropsIdsAsync(studentsIds, studentGroupsIds);
            }

            if (request.IncludeAnalytics.Contains(StudentResultType.AverageStudentVisits))
            {
                result.AverageStudentVisits = await _dashboardRepository
                                              .GetStudentsAverageVisitsByStudentIdsAndGroupsIdsAsync(studentsIds, studentGroupsIds);
            }

            return(Result <StudentsResultsDto> .GetSuccess(result));
        }
        public async Task <ActionResult> GetStudentsResults([FromBody] StudentsRequestDto <StudentResultType> request)
        {
            var results = await _dashboardService
                          .GetStudentsResultAsync(request);

            return(results.ToActionResult());
        }
Exemple #3
0
        private IEnumerable <string> ValidateStudentsRequest <T>(StudentsRequestDto <T> request)
            where T : Enum
        {
            if (request == default)
            {
                yield return("Please provide request data");

                yield break;
            }

            if (request.IncludeAnalytics == default || request.IncludeAnalytics.Length == 0)
            {
                yield return("Please provide 'IncludeAnalytics' parameters");
            }

            if (!request.CourseId.HasValue && !request.StudentGroupId.HasValue)
            {
                yield return("Please provide course or student group id");
            }
        }