/// <summary>
        /// Gets the progress statement for the person for this achievement. Flat means that the unmet prerequisites are not computed.
        /// </summary>
        /// <param name="streakTypeAchievementTypeCache">The streak type achievement type cache.</param>
        /// <param name="personId">The person identifier.</param>
        /// <returns></returns>
        private ProgressStatement GetFlatProgressStatement(StreakTypeAchievementTypeCache streakTypeAchievementTypeCache, int personId)
        {
            var rockContext    = Context as RockContext;
            var attemptService = new StreakAchievementAttemptService(rockContext);

            var attempts = attemptService.Queryable()
                           .AsNoTracking()
                           .Where(saa =>
                                  saa.StreakTypeAchievementTypeId == streakTypeAchievementTypeCache.Id &&
                                  saa.Streak.PersonAlias.PersonId == personId)
                           .OrderByDescending(saa => saa.AchievementAttemptStartDateTime)
                           .ToList();

            var progressStatement = new ProgressStatement(streakTypeAchievementTypeCache);

            // If there are no attempts, no other information can be derived
            if (!attempts.Any())
            {
                return(progressStatement);
            }

            var mostRecentAttempt = attempts.First();
            var bestAttempt       = attempts.OrderByDescending(saa => saa.Progress).First();

            progressStatement.SuccessCount      = attempts.Count(saa => saa.IsSuccessful);
            progressStatement.AttemptCount      = attempts.Count();
            progressStatement.BestAttempt       = bestAttempt;
            progressStatement.MostRecentAttempt = mostRecentAttempt;

            return(progressStatement);
        }
示例#2
0
        /// <summary>
        /// Gets the progress statement for the achiever for this achievement. Flat means that the unmet prerequisites are not computed.
        /// </summary>
        /// <param name="achievementTypeCache">The achievement type cache.</param>
        /// <param name="achieverEntityId">The achiever entity identifier.</param>
        /// <returns></returns>
        private ProgressStatement GetFlatProgressStatement(AchievementTypeCache achievementTypeCache, int achieverEntityId)
        {
            var rockContext    = Context as RockContext;
            var attemptService = new AchievementAttemptService(rockContext);

            var attemptsQuery = attemptService.Queryable().AsNoTracking();

            var attempts = attemptService.GetOrderedAchieverAttempts(attemptsQuery, achievementTypeCache, achieverEntityId);

            var progressStatement = new ProgressStatement(achievementTypeCache);

            // If there are no attempts, no other information can be derived
            if (!attempts.Any())
            {
                return(progressStatement);
            }

            var mostRecentAttempt = attempts.First();
            var bestAttempt       = attempts.OrderByDescending(saa => saa.Progress).First();

            progressStatement.SuccessCount      = attempts.Count(saa => saa.IsSuccessful);
            progressStatement.AttemptCount      = attempts.Count();
            progressStatement.BestAttempt       = bestAttempt;
            progressStatement.MostRecentAttempt = mostRecentAttempt;

            return(progressStatement);
        }