public async Task <IEnumerable <ScoringAssessmentDTO> > Search(ScoringAssessmentSearchParams searchParams)
        {
            if (searchParams.GetFromCache)
            {
                var scoringsFromCache = await GetAssessmentScoringsFromCacheOrDefault(searchParams.UniqueSectionCode);

                if (scoringsFromCache != null && scoringsFromCache.Count() > 0)
                {
                    var scoringsFromCacheList = scoringsFromCache
                                                .OrderBy(student => student.Student.LastSurname)
                                                .ToList();

                    return(await ApplyFilters(scoringsFromCacheList, searchParams));
                }
            }

            var scoringsFromApi   = new List <ScoringAssessmentDTO>();
            var studentsBySection = await _students.GetStudentsBySectionId(searchParams.UniqueSectionCode);

            foreach (var student in studentsBySection)
            {
                try
                {
                    var studentDTO     = _mapper.MapStudentDTO(student);
                    var associationDTO = await GetAssessmentScoringsByStudent(studentDTO, searchParams.Category);

                    scoringsFromApi.Add(associationDTO);
                }
                catch (Exception ex)
                {
                    // If an error ocurres when generating the scorings, skip and continue looping
                }
            }

            if (searchParams.StoreInCache)
            {
                string key = CacheKeys.Composed(CacheKeys.AssessmentScoringsBySectionUniqueId, searchParams.UniqueSectionCode);
                bool   successfullyCachedScorings = await _cache.TrySet(key, scoringsFromApi);
            }

            return(await ApplyFilters(scoringsFromApi, searchParams));
        }
        private async Task <IEnumerable <ScoringAssessmentDTO> > ApplyFilters(IEnumerable <ScoringAssessmentDTO> scorings, ScoringAssessmentSearchParams searchParams)
        {
            scorings = string.IsNullOrWhiteSpace(searchParams.Category)
                ? scorings
                : FilterByCategoryDescriptor(scorings, searchParams.Category);

            scorings = searchParams.OnlyFromCurrentNamespace.HasValue
                ? await FilterByNamespace(scorings, searchParams.OnlyFromCurrentNamespace.Value)
                : scorings;

            // Remove sensitive data
            scorings = scorings.Select(scoring =>
            {
                scoring.Student = _mapper.SecuredStudentDTO(scoring.Student);
                return(scoring);
            }).ToList();

            // Add score result if none existent
            foreach (var scoring in scorings)
            {
                foreach (var association in scoring.Associations)
                {
                    if (association.AssociationModel.ScoreResults.Count == 0)
                    {
                        var score = association.Assessment.Scores?.FirstOrDefault();
                        association.AssociationModel.ScoreResults.Add(new StudentAssessmentScoreResultsItem
                        {
                            AssessmentReportingMethodType = score?.AssessmentReportingMethodType ?? "Raw Score",
                            Result             = "",
                            ResultDatatypeType = score?.ResultDatatypeType ?? "Integer",
                        });
                    }
                }
            }

            return(scorings);
        }
Esempio n. 3
0
        private async Task <IEnumerable <ScoringAssessmentDTO> > ApplyFilters(IEnumerable <ScoringAssessmentDTO> scorings, ScoringAssessmentSearchParams searchParams)
        {
            scorings = string.IsNullOrWhiteSpace(searchParams.Category)
                ? scorings
                : FilterByCategoryDescriptor(scorings, searchParams.Category);

            scorings = searchParams.OnlyFromCurrentNamespace.HasValue
                ? await FilterByNamespace(scorings, searchParams.OnlyFromCurrentNamespace.Value)
                : scorings;

            // Remove sensitive data
            scorings = scorings.Select(scoring =>
            {
                scoring.Student = _mapper.SecuredStudentDTO(scoring.Student);
                return(scoring);
            }).ToList();

            return(scorings);
        }