/// <summary>
        /// Gets the unpublished achievements newer than the given date.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <param name="oldestDate">The oldest date.</param>
        /// <param name="language">The language.</param>
        /// <returns>
        /// The achievements that haven't been published yet.
        /// </returns>
        public ICollection <Achievement> GetUnpublishedAchievements(string steamUserId, DateTime?oldestDate, string language = null)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            if (language == null)
            {
                language = CultureHelper.GetLanguage();
            }

            IEnumerable <Game> games = _communityService.GetGames(steamUserId, language);

            ICollection <Data.Achievement> dataAchievements;

            if (oldestDate == null)
            {
                dataAchievements = _achievementManager.GetUnpublishedAchievements(steamUserId);
            }
            else
            {
                dataAchievements = _achievementManager.GetUnpublishedAchievements(steamUserId, oldestDate.Value);
            }

            IEnumerable <Data.Achievement> missingNames =
                dataAchievements.Where(a => !a.AchievementNames.Where(n => n.Language == language).Any());

            if (missingNames.Any())
            {
                IEnumerable <Achievement> communityAchievements =
                    _communityService.GetAchievements(steamUserId, language)
                    .Select(ua => ua.Achievement);

                foreach (Data.Achievement achievement in missingNames)
                {
                    Achievement missing =
                        communityAchievements
                        .Where(a => a.Game.Id == achievement.GameId && a.ApiName == achievement.ApiName)
                        .SingleOrDefault();

                    if (missing != null)
                    {
                        achievement.AchievementNames.Add(new AchievementName
                        {
                            Language    = language,
                            Name        = missing.Name,
                            Description = missing.Description
                        });
                    }
                }
            }

            List <Achievement> achievements = dataAchievements.ToSimpleAchievementList(games, language);

            return(achievements);
        }
Esempio n. 2
0
        public List<SimpleAchievement> GetNewAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            return _achievementManager.GetUnpublishedAchievements(steamUserId).ToSimpleAchievementList();
        }
Esempio n. 3
0
        public List <SimpleAchievement> GetNewAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            IEnumerable <Game> games = _communityService.GetGames(steamUserId);

            return(_achievementManager.GetUnpublishedAchievements(steamUserId).ToSimpleAchievementList(games));
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the unpublished achievements newer than the given date.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <param name="oldestDate">The oldest date.</param>
        /// <returns>
        /// The achievements that haven't been published yet.
        /// </returns>
        public ICollection <Achievement> GetUnpublishedAchievements(string steamUserId, DateTime?oldestDate)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            IEnumerable <Game> games = _communityService.GetGames(steamUserId);

            ICollection <Data.Achievement> achievements;

            if (oldestDate == null)
            {
                achievements = _achievementManager.GetUnpublishedAchievements(steamUserId);
            }
            else
            {
                achievements = _achievementManager.GetUnpublishedAchievements(steamUserId, oldestDate.Value);
            }

            return(achievements.ToSimpleAchievementList(games));
        }
        /// <summary>
        /// Gets the unpublished achievements newer than the given date.
        /// </summary>
        /// <param name="facebookUserId"> </param>
        /// <param name="oldestDate">The oldest date.</param>
        /// <param name="language">The language.</param>
        /// <returns>
        /// The achievements that haven't been published yet.
        /// </returns>
        public ICollection <Models.Achievement> GetUnpublishedAchievements(long facebookUserId, DateTime?oldestDate,
                                                                           string language = null)
        {
            if (language == null)
            {
                language = CultureHelper.GetLanguage();
            }

            string steamUserId = GetSteamUserId(facebookUserId);

            IEnumerable <Game> games = _communityService.GetGames(steamUserId, language);

            ICollection <Data.Achievement> dataAchievements;

            if (oldestDate == null)
            {
                dataAchievements = _achievementManager.GetUnpublishedAchievements(facebookUserId);
            }
            else
            {
                dataAchievements = _achievementManager.GetUnpublishedAchievements(facebookUserId, oldestDate.Value);
            }

            IEnumerable <Data.Achievement> missingNames =
                dataAchievements.Where(a => !a.AchievementNames.Where(n => n.Language == language).Any());

            if (missingNames.Any())
            {
                IEnumerable <Models.Achievement> communityAchievements =
                    _communityService.GetAchievements(steamUserId, language)
                    .Select(ua => ua.Achievement);

                foreach (Data.Achievement achievement in missingNames)
                {
                    Models.Achievement missing =
                        communityAchievements
                        .Where(a => a.Game.Id == achievement.GameId && a.ApiName == achievement.ApiName)
                        .SingleOrDefault();

                    if (missing != null)
                    {
                        achievement.AchievementNames.Add(new AchievementName
                        {
                            Language    = language,
                            Name        = missing.Name,
                            Description = missing.Description
                        });
                    }
                }
            }

            ICollection <Models.Achievement> achievements = Mapper.Map <ICollection <Models.Achievement> >(dataAchievements);

            // set game
            foreach (var dataAchievement in dataAchievements)
            {
                var achievement = achievements.Where(a => a.Id == dataAchievement.Id).SingleOrDefault();
                if (achievement != null)
                {
                    achievement.Game = games.Where(g => g.Id == dataAchievement.GameId).SingleOrDefault();
                }
            }

            return(achievements.Where(a => a.Game != null)
                   .OrderBy(a => a.Game.Name).ThenBy(a => a.Name).ToList());
        }