Exemplo n.º 1
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);
        }