private PlayerLibraryResponse GetGamerSteamLibrary(gamer gamer) { var url = GetSteamLibaryUrl(gamer.steam_id); var client = new WebClient(); var data = client.DownloadString(url); var apiResponse = JsonConvert.DeserializeObject <ApiPlayerLibraryResponse>(data); return(apiResponse.response); }
private void UpdateExistingGamerGames(gamer gamer, PlayerLibraryResponse steamGames, List <gamer_games> gamerGames) { foreach (var gamerGame in gamerGames) { gamerGame.time_played = steamGames.games.Where(x => x.appid == gamerGame.game.steam_id).FirstOrDefault().playtime_forever; } _context.SaveChanges(); }
private bool RefreshGamerGames(gamer gamer) { var gamesFromSteam = GetGamerSteamLibrary(gamer); var gamerGames = GetGamerGameList(gamer.id); AddNewGamerGames(gamer, gamesFromSteam, gamerGames); UpdateExistingGamerGames(gamer, gamesFromSteam, gamerGames); UpdateGamerUpdatedAt(gamer); return(true); }
private gamer SummaryToGamer(PlayerSummaryResponse summary) { var gamer = new gamer(); gamer.steam_id = summary.players[0].steamid; gamer.avatar = summary.players[0].avatar; gamer.avatar_medium = summary.players[0].avatarmedium; gamer.name = summary.players[0].personaname; gamer.created_at = DateTime.Now; gamer.updated_at = DateTime.Now; return(gamer); }
private void AddNewGamerGames(gamer gamer, PlayerLibraryResponse steamGames, List <gamer_games> gamerGames) { var newGames = steamGames.games.Where(x => !gamerGames.Any(y => y.game.steam_id == x.appid)) .ToList(); var newGameAppIds = newGames.Select(x => x.appid).ToList(); var games = _context.games.Where(x => newGameAppIds.Contains(x.steam_id)) .ToList(); foreach (var game in games) { _context.gamer_games.Add(new gamer_games { gamer_id = gamer.id, game_id = game.id, time_played = newGames.Where(x => x.appid == game.steam_id).FirstOrDefault().playtime_forever, created_at = DateTime.Now, updated_at = DateTime.Now }); } _context.SaveChanges(); }
public bool RefreshGamerSteamLibrary(gamer gamer) { GetGamerSteamLibrary(gamer); return(true); }
private bool GamerGamesNeedRefresh(gamer gamer) { bool requiresRefresh = DateTime.Today - gamer.updated_at.Date >= TimeSpan.FromHours(8); return(requiresRefresh); }
private void UpdateGamerUpdatedAt(gamer gamer) { gamer.updated_at = DateTime.Now; _context.SaveChanges(); }