コード例 #1
0
        private NhlGameDto CreateGameDto(NhlShortGame nhlShortGame, bool loadPlayers)
        {
            if (loadPlayers)
            {
                return(CreateGameDtoWithPlayers(nhlShortGame));
            }

            return(CreateGameDtoWithoutPlayers(nhlShortGame));
        }
コード例 #2
0
        private NhlGameDto CreateGameDtoWithoutPlayers(NhlShortGame nhlShortGame)
        {
            Guid     gameId        = nhlShortGame.GameId;
            DateTime startDateTime = nhlShortGame.StartDateTime;
            Guid     homeTeamId    = nhlShortGame.HomeTeamId;
            Guid     awayTeamId    = nhlShortGame.AwayTeamId;

            TeamDto homeTeam = GetTeam(homeTeamId);
            TeamDto awayTeam = GetTeam(awayTeamId);

            NhlGameDto nhlGameDto = new NhlGameDto
            {
                GameId        = gameId,
                StartDateTime = startDateTime,
                HomeTeam      = homeTeam,
                AwayTeam      = awayTeam
            };

            return(nhlGameDto);
        }
コード例 #3
0
        private NhlGameDto CreateGameDtoWithPlayers(NhlShortGame nhlShortGame)
        {
            Guid     gameId        = nhlShortGame.GameId;
            DateTime startDateTime = nhlShortGame.StartDateTime;
            Guid     homeTeamId    = nhlShortGame.HomeTeamId;
            Guid     awayTeamId    = nhlShortGame.AwayTeamId;

            TeamDto homeTeam = GetTeam(homeTeamId);
            TeamDto awayTeam = GetTeam(awayTeamId);

            List <PlayerDto> homePlayerList = GetPlayers(homeTeamId);
            List <PlayerDto> awayPlayerList = GetPlayers(awayTeamId);

            if (homePlayerList == null || homePlayerList.Count == 0)
            {
                Logger.Info("CreateGameDtoWithPlayers() error: homePlayerList is null or empty");
            }

            if (awayPlayerList == null || awayPlayerList.Count == 0)
            {
                Logger.Info("CreateGameDtoWithPlayers() error: awayPlayerList is null or empty");
            }

            homeTeam.PlayerList = homePlayerList;
            awayTeam.PlayerList = awayPlayerList;

            NhlGameDto nhlGameDto = new NhlGameDto
            {
                GameId        = gameId,
                StartDateTime = startDateTime,
                HomeTeam      = homeTeam,
                AwayTeam      = awayTeam
            };

            return(nhlGameDto);
        }
コード例 #4
0
        public List <NhlGameDto> GetGames(int numberGameDays, bool loadPlayers)
        {
            lock (_lockObject)
            {
                //
                // loadPlayers = true;
                List <NhlShortGame> nhlShortGameList = new List <NhlShortGame>();
                List <NhlGameDto>   nhlGameDtoList   = new List <NhlGameDto>();

                using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnectionString))
                {
                    npgsqlConnection.Open();
                    //  const string sqlCommandText = "select * from nhl.get_games(@number_game_days)";
                    const string sqlCommandText = @"select * from nhl.game where
                    date(start_time - interval '8 hour') >= date(timezone('utc', now() - interval '10 hour'))  and
                    date(start_time - interval '8 hour')  <= date(start_time + interval '3 Day' - interval '8 hour')
                    order by start_time asc limit 10;";
                    using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(sqlCommandText, npgsqlConnection))
                    {
                        npgsqlCommand.CommandType = CommandType.Text;

                        NpgsqlParameter npgsqlParameter1 = new NpgsqlParameter("number_game_days", numberGameDays);
                        npgsqlCommand.Parameters.Add(npgsqlParameter1);

                        using (NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader())
                        {
                            if (!npgsqlDataReader.HasRows)
                            {
                                const string message = "GetGames() has no rows";
                                Logger.Info(message);

                                return(nhlGameDtoList);
                            }

                            while (npgsqlDataReader.Read())
                            {
                                Guid     gameId        = npgsqlDataReader.GetGuid("game_id");
                                DateTime startDateTime = npgsqlDataReader.GetDateTime("start_time");
                                Guid     homeTeamId    = npgsqlDataReader.GetGuid("home_id");
                                Guid     awayTeamId    = npgsqlDataReader.GetGuid("away_id");

                                NhlShortGame nhlShortGame = new NhlShortGame
                                {
                                    GameId        = gameId,
                                    StartDateTime = startDateTime,
                                    HomeTeamId    = homeTeamId,
                                    AwayTeamId    = awayTeamId
                                };

                                nhlShortGameList.Add(nhlShortGame);
                            }
                        }
                    }
                }

                foreach (NhlShortGame nhlShortGame in nhlShortGameList)
                {
                    NhlGameDto nhlGameDto = CreateGameDto(nhlShortGame, loadPlayers);
                    nhlGameDtoList.Add(nhlGameDto);
                }

                return(nhlGameDtoList);
            }
        }