Ejemplo n.º 1
0
        public async Task <StatusSummary> GetCurrentStatsAsync(StatusSummary request)
        {
            if (request.SiteId == null ||
                request.SiteId != GetCurrentSiteId())
            {
                request.SiteId = GetCurrentSiteId();
            }
            string cacheKey = $"{CacheKey.CurrentStats}s{request.SiteId}p{request.ProgramId}sys{request.SystemId}b{request.BranchId}";
            var    summary  = _memoryCache.Get <StatusSummary>(cacheKey);

            if (summary == null)
            {
                summary = request;
                summary.RegisteredUsers = await _userRepository.GetCountAsync(request);

                summary.PointsEarned = await _userLogRepository.PointsEarnedTotalAsync(request);

                summary.ActivityEarnings = await _userLogRepository
                                           .ActivityEarningsTotalAsync(request);

                summary.CompletedChallenges = await _userLogRepository
                                              .CompletedChallengeCountAsync(request);

                summary.BadgesEarned = await _userLogRepository.EarnedBadgeCountAsync(request);

                summary.DaysUntilEnd = await GetDaysUntilEnd();

                _memoryCache.Set(cacheKey,
                                 summary,
                                 new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5)));
            }
            return(summary);
        }