public virtual IEnumerable<AwardedAchievement> Calculate(Activity trigger)
        {
            List<AwardedAchievement> awardedAchievements = new List<AwardedAchievement>();

            IEnumerable<Achievement> achievements = GetApplicableAchievements(trigger);

            foreach (Achievement achievement in achievements)
            {
                Achievement achievementCopy = achievement;
                AwardedAchievement awardedAchievement =
                    Repository
                        .Query<AwardedAchievement>()
                        .SingleOrDefault(x => x.Achievement == achievementCopy && x.Developer == trigger.Developer);

                if (awardedAchievement == null)
                {
                    awardedAchievement = new AwardedAchievement()
                                             {
                                                 Achievement = achievement,
                                                 Count = 0,
                                                 Developer = trigger.Developer,
                                             };
                }

                awardedAchievement.Count += 1;
                awardedAchievement.LastAwardedTimestamp = DateTime.Now;

                awardedAchievements.Add(awardedAchievement);
            }

            return awardedAchievements;
        }
Пример #2
0
        private void GiveAchievement(AccountGroupPerson accountGroupPerson, Achievement achievement, DateTime awardedOn)
        {
            PersonWallet wallet = accountGroupPerson.Person.Wallets.Single(x => x.AccountGroupId == accountGroupPerson.AccountGroupId);

            wallet.Value += achievement.Value;
            AwardedAchievement award = new AwardedAchievement()
            {
                Achievement   = achievement,
                AchievementId = achievement.Id,
                AwardDate     = awardedOn,
            };

            Context.Add(award);
            Context.SaveChanges();
        }