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 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(); }