public async Task CacheScoringInterventions(ScoringInterventionSearchFilters filters)
        {
            var associations = await ScoringInterventionsService.GetStudentInterventionsDTO(filters, getFromCache : false);

            string key = CacheKeys.Composed(CacheKeys.InterventionScoringsBySectionUniqueId, filters.SectionId);
            await _cache.Set(key, associations);
        }
예제 #2
0
        public async Task RefreshScoringInterventions()
        {
            var sections = await _catalog.GetSectionsAll(getFromCache : false, storeInCache : false);

            foreach (var section in sections)
            {
                var filters = new ScoringInterventionSearchFilters(section.Id);
                var studentInterventionAssociations = await _scoringInterventions.GetStudentInterventionsDTO(filters, getFromCache : false, storeInCache : false);

                string key = CacheKeys.Composed(CacheKeys.InterventionScoringsBySectionUniqueId, section.Id);
                await _cache.TrySet(key, studentInterventionAssociations);

                string refreshDateKey = CacheKeys.Composed(CacheKeys.RefreshDates.InterventionScoringsBySectionUniqueId, section.Id);
                await UpdateLastRefreshedDate(refreshDateKey);
            }
        }
예제 #3
0
        public async Task <IEnumerable <StudentInterventionsDTO> > GetStudentInterventionsDTO(ScoringInterventionSearchFilters filters, bool getFromCache = true, bool storeInCache = true)
        {
            if (getFromCache)
            {
                try
                {
                    var fromCache = await GetStudentInterventionsDTOFromCacheOrDefaultOrThrowJsonReaderException(filters.SectionId);

                    if (fromCache != null && fromCache.Count() > 0)
                    {
                        return(fromCache);
                    }

                    storeInCache = true;
                }
                catch (JsonReaderException ex)
                {
                    storeInCache = true;
                }
            }

            var associations      = new List <StudentInterventionsDTO>();
            var studentsBySection = await _students.GetStudentsBySectionId(filters.SectionId);

            foreach (var student in studentsBySection)
            {
                var association = await GetStudentInterventionsDTOByStudent(student.StudentUniqueId);

                associations.Add(association);
            }

            if (storeInCache)
            {
                try
                {
                    string key = CacheKeys.Composed(CacheKeys.InterventionScoringsBySectionUniqueId, filters.SectionId);
                    await _cacheProvider.Set(key, associations);
                }
                catch (Exception ex)
                {
                    // Sometimes caching takes too long so request timeout will expire
                    // causing the method th throw an exception. Catch the error to return
                    // the scorings back to the frontend even though this error happens
                }
            }

            return(associations
                   .OrderBy(student => student.Student.LastSurname)
                   .ToList());
        }
        public async Task <ActionResult> CacheScoringInterventions([FromBody] ScoringInterventionSearchFilters filters)
        {
            await _cacheService.CacheScoringInterventions(filters);

            return(Ok());
        }
예제 #5
0
 public async Task <IEnumerable <StudentInterventionsDTO> > GetScorings([FromBody] ScoringInterventionSearchFilters filters, [FromQuery] bool getFromCache = true, [FromQuery] bool storeInCache = true)
 {
     return(await ScoringInterventionsService.GetStudentInterventionsDTO(filters, getFromCache, storeInCache));
 }