Example #1
0
        public List <UserAppPlaytime> GetRecentlyPlayedGames(long userID)
        {
            DataCacheRepository repo  = _uow.GetRepo <DataCacheRepository>();
            DataCache           cache = repo.Get(userID, CacheType.SteamUserAppPlaytime);

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

            List <UserAppPlaytime> recentGames = _steamApi.GetRecentlyPlayedGames(userID);

            bool isNew = cache == null;

            cache = new DataCache {
                EntityID    = userID.ToString(),
                CacheTypeID = CacheType.SteamUserGameStats,
                StoredOn    = DateTime.Now,
                JsonData    = JsonConvert.SerializeObject(recentGames)
            };

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

            return(recentGames);
        }