コード例 #1
0
        /// <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>
        /// Deletes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public override bool Delete(Streak item)
        {
            // Since Entity Framework cannot cascade delete achievement attempts because of a possible circular reference,
            // we need to delete them here
            var attemptService = new StreakAchievementAttemptService(Context as RockContext);
            var attempts       = attemptService.Queryable().Where(a => a.StreakId == item.Id);

            attemptService.DeleteRange(attempts);

            // Now we can delete the streak as normal
            return(base.Delete(item));
        }