Beispiel #1
0
        public static void AddNewPlayer(PlayerInfo player)
        {
            using var db = new EspnDB();
            if (!IsPlayerExist(player.Player.Id))
            {
                db.Players.Add(player.Player);
                db.SaveChanges();
            }
            else
            {
                if (!ConfigurationManager.AppSettings["updateExistPlayer"].ToBool())
                {
                    return;
                }
            }

            foreach (Game game in player.Games)
            {
                if (IsGameExist(player.Player.Id, game.GameDate))
                {
                    continue;
                }
                game.Pk = GetNextGamePk();
                db.Games.Add(game);
            }
            db.SaveChanges();
            Console.WriteLine($"Player {player.Player.Name} Uploaded To DB");
        }
Beispiel #2
0
        public static void UpdatePlayersGames(PlayerInfo[] players)
        {
            using var db = new EspnDB();

            var dbPlayers  = db.Players.ToArray();
            var newPlayers = players.Where(p => !IsPlayerExist(p.Player, dbPlayers)).Select(p => p.Player).ToArray();

            if (newPlayers.Any())
            {
                db.Players.AddRange(newPlayers);
                db.SaveChanges();
                Console.WriteLine($"{newPlayers.Length} New Players Uploaded To DB");
            }

            var dbGames = db.Games.ToArray();

            Console.WriteLine($"Found {dbGames.Length} Games in DB, Search For New Games");
            var playerGames = players.SelectMany(p => p.Games).ToArray();
            var newGames    = playerGames.Where(g => !IsGameExist(g, dbGames)).ToArray();

            Console.WriteLine($"Found {newGames.Length} New Games, Start Upload To DB");
            foreach (Game newGame in newGames)
            {
                newGame.Pk = GetNextGamePk();
                db.Games.Add(newGame);
            }
            db.SaveChanges();
            Console.WriteLine($"{newGames.Length} New Games Uploaded To DB");
        }