Example #1
0
        public OwnedAppInfoViewModel Load(long steamID, long appID, LogicService logicService)
        {
            SteamUserDetails = logicService.SteamLogic.GetByUserID(steamID, reloadWishlistPrices: true);
            List <UserAppPlaytime> recents = logicService.SteamLogic.GetRecentlyPlayedGames(steamID);

            if (recents.Any())
            {
                UserAppPlaytime recent = recents.SingleOrDefault(x => x.AppID == appID);
                UserAppPlaytime = recent;
            }
            OwnedApp = SteamUserDetails.OwnedApps.SingleOrDefault(x => x.AppID == appID);
            Stats    = logicService.SteamLogic.GetByUserAndAppID(steamID, appID);
            return(this);
        }
Example #2
0
        public SteamUserGameStats GetByUserAndAppID(long userID, long appID)
        {
            DataCacheRepository repo  = _uow.GetRepo <DataCacheRepository>();
            DataCache           cache = repo.Get(userID, appID, CacheType.SteamUserGameStats);

            if (cache != null && cache.StoredOn > DateTime.Now.AddDays(-1))
            {
                SteamUserGameStats user = cache.Deserialize <SteamUserGameStats>();
                return(user);
            }

            SteamUserGameStats stats = new SteamUserGameStats {
                UserGameStats   = _steamApi.GetUserStatsForGame(userID, appID),
                GameStatsSchema = _steamApi.GetSchemaForGame(appID)
            };

            bool isNew = cache == null;

            cache = new DataCache {
                EntityID    = userID + "|" + appID,
                CacheTypeID = CacheType.SteamUserGameStats,
                StoredOn    = DateTime.Now,
                JsonData    = JsonConvert.SerializeObject(stats)
            };

            if (isNew)
            {
                repo.Add(cache);
            }
            else
            {
                repo.Update(cache);
            }

            return(stats);
        }