Ejemplo n.º 1
0
        private NcaabbGameDto CreateGame(NcaabbShortGame ncaabbShortGame)
        {
            Guid     gameId        = ncaabbShortGame.GameId;
            DateTime startDateTime = ncaabbShortGame.StartDateTime;
            Guid     homeTeamId    = ncaabbShortGame.HomeTeamId;
            Guid     awayTeamId    = ncaabbShortGame.AwayTeamId;

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

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

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

            NcaabbGameDto ncaabbGameDto = new NcaabbGameDto
            {
                GameId        = gameId,
                StartDateTime = startDateTime,
                HomeTeam      = homeTeam,
                AwayTeam      = awayTeam
            };

            return(ncaabbGameDto);
        }
Ejemplo n.º 2
0
        public List <NcaabbGameDto> GetGames(int numberGameDays, bool loadPlayers)
        {
            lock (_lockObject)
            {
                List <NcaabbShortGame> ncaabbShortGameList = new List <NcaabbShortGame>();
                List <NcaabbGameDto>   ncaabbGameList      = new List <NcaabbGameDto>();

                using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnectionString))
                {
                    npgsqlConnection.Open();
                    const string sqlCommandText = "select * from ncaabb.get_games(@number_game_days)";

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

                            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");

                                NcaabbShortGame ncaabbShortGame = new NcaabbShortGame
                                {
                                    GameId        = gameId,
                                    StartDateTime = startDateTime,
                                    HomeTeamId    = homeTeamId,
                                    AwayTeamId    = awayTeamId
                                };

                                ncaabbShortGameList.Add(ncaabbShortGame);
                            }
                        }
                    }
                }

                foreach (NcaabbShortGame ncaabbShortGame in ncaabbShortGameList)
                {
                    NcaabbGameDto ncaabbGame = CreateGame(ncaabbShortGame);
                    ncaabbGameList.Add(ncaabbGame);
                }

                return(ncaabbGameList);
            }
        }