Пример #1
0
 private game_type AddOrLoadGameType(game_type gameType)
 {
     if (!context.game_type.Any(p => p.game_type_name == gameType.game_type_name))
     {
         gameType = context.game_type.Add(gameType);
     }
     else
     {
         gameType = context.game_type.First(type => type.game_type_name == type.game_type_name);
     }
     return gameType;
 }
Пример #2
0
        public void AddGame(player_information whitePlayerInformation, player_information blackPlayerInformation, game_type gameType, List<game_move> gameMoves, int gameSize, string gameResult, int moveCount, DateTime startDate)
        {
            try
            {
                game game = new game();

                whitePlayerInformation.player = AddOrLoadPlayer(whitePlayerInformation.player);
                whitePlayerInformation.algorithm = AddOrLoadAlgorithm(whitePlayerInformation.algorithm);
                whitePlayerInformation = AddOrLoadPlayerInformation(whitePlayerInformation);

                context.SaveChanges();

                blackPlayerInformation.player = AddOrLoadPlayer(blackPlayerInformation.player);
                blackPlayerInformation.algorithm = AddOrLoadAlgorithm(blackPlayerInformation.algorithm);
                blackPlayerInformation = AddOrLoadPlayerInformation(blackPlayerInformation);

                context.SaveChanges();

                game.white_player_information_id = whitePlayerInformation.player_information_id;
                game.black_player_information_id = blackPlayerInformation.player_information_id;
                game.game_type = AddOrLoadGameType(gameType);
                game.game_size = gameSize;
                game.game_result = gameResult;
                game.move_count = moveCount;
                game.start_date = startDate;

                game = context.games.Add(game);

                foreach (var game_move in gameMoves)
                {
                    game_move.game_id = game.game_id;
                    context.game_move.Add(game_move);
                }

                context.SaveChanges();
            }
            catch (Exception)
            {
                //TODO: obsługa błędu połączenia z bazą danych   
            }
        }