Esempio n. 1
0
        public async Task <List <Player> > GetAllAsync()
        {
            Logger.LogDebug($"Getting all players from '{MetadataResolver.TableName<PlayerSql>()}' table.");

            List <PlayerSql> sqlEntries = await DbConnection.Select <PlayerSql>().ExecuteAsync();

            return(sqlEntries.Select(PlayerSql.ToCoreEntity).ToList());
        }
Esempio n. 2
0
        public async Task <List <TeamWeekStats> > GetAsync(WeekInfo week)
        {
            Logger.LogDebug($"Getting team stats for '{week}' from '{MetadataResolver.TableName<TeamGameStatsSql>()}' table.");

            List <TeamGameStatsSql> sqlEntries = await DbConnection.Select <TeamGameStatsSql>()
                                                 .Where(s => s.Season == week.Season && s.Week == week.Week)
                                                 .ExecuteAsync();

            return(sqlEntries.Select(TeamGameStatsSql.ToCoreEntity).ToList());
        }
Esempio n. 3
0
        public async Task <List <WeekMatchup> > GetAsync(WeekInfo week)
        {
            Logger.LogDebug($"Retrieving week matchups for week '{week}' from '{MetadataResolver.TableName<WeekGameMatchupSql>()}' table.");

            List <WeekGameMatchupSql> matchups = await DbConnection.Select <WeekGameMatchupSql>()
                                                 .Where(m => m.Season == week.Season && m.Week == week.Week)
                                                 .ExecuteAsync();

            return(matchups.Select(WeekGameMatchupSql.ToCoreEntity).ToList());
        }
Esempio n. 4
0
        private void AppendSelectFrom(List <Expression <Func <TEntity, object> > > propertySelections)
        {
            propertySelections?.ForEach(PropertySelectionResolver.ValidatePropertyExpression);

            var table      = MetadataResolver.TableName <TEntity>();
            var selections = PropertySelectionResolver.GetSelectionsFromProperties(propertySelections);

            string selectFrom = $"SELECT {selections} FROM {table}";

            _sqlBuilder.Append(selectFrom);
        }
Esempio n. 5
0
        public Task AddAsync(PlayerAdd player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player), "Player add must be provided.");
            }

            Logger.LogDebug($"Adding player '{player}' to '{MetadataResolver.TableName<PlayerSql>()}' table.");

            PlayerSql sqlEntry = PlayerSql.FromCoreAddEntity(player);

            return(DbConnection.Insert(sqlEntry).ExecuteAsync());
        }
Esempio n. 6
0
        public Task AddAsync(List <WeekMatchup> matchups)
        {
            if (matchups == null)
            {
                throw new ArgumentNullException(nameof(matchups), "Week matchups must be provided.");
            }

            Logger.LogDebug($"Adding {matchups.Count} week matchups to '{MetadataResolver.TableName<WeekGameMatchupSql>()}' table.");

            var sqlEntries = matchups.Select(WeekGameMatchupSql.FromCoreEntity).ToList();

            return(DbConnection.InsertMany(sqlEntries).ExecuteAsync());
        }
Esempio n. 7
0
        public TableExistsQuery(Func <NpgsqlConnection> getConnection)
        {
            _getConnection = getConnection ?? throw new ArgumentNullException(nameof(getConnection));

            var fullTableIdentifier = MetadataResolver.TableName <TEntity>();

            var split     = fullTableIdentifier.Split('.');
            var schema    = split[0];
            var tableName = split[1];

            var innerQuery = "SELECT 1 FROM pg_tables "
                             + $"WHERE schemaname = '{schema}' AND tablename = '{tableName}'";

            _sqlBuilder.Append($"SELECT EXISTS({innerQuery})");
        }
Esempio n. 8
0
        public async Task AddAsync(List <Team> teams)
        {
            if (teams == null)
            {
                throw new ArgumentNullException(nameof(teams), "Teams must be provided.");
            }

            if (!teams.Any())
            {
                return;
            }

            var sqlEntries = teams.Select(TeamSql.FromCoreEntity).ToList();

            Logger.LogDebug($"Adding {sqlEntries.Count} teams to '{MetadataResolver.TableName<TeamSql>()}' table.");

            await DbConnection.InsertMany(sqlEntries).ExecuteAsync();
        }
Esempio n. 9
0
        public Task UpdateAsync(Guid id, PlayerUpdate update)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("Player id must be provided.", nameof(id));
            }
            if (update == null)
            {
                throw new ArgumentNullException(nameof(update), "Update must be provided.");
            }

            Logger.LogDebug($"Updating player '{id}' in '{MetadataResolver.TableName<PlayerSql>()}' table.");

            return(DbConnection.Update <PlayerSql>()
                   .Where(p => p.Id == id)
                   .Set(p => p.Number, update.Number)
                   .Set(p => p.Position, update.Position)
                   .Set(p => p.Status, update.Status)
                   .ExecuteAsync());
        }
Esempio n. 10
0
        public async Task UpdateRosterMappingsAsync(List <Roster> rosters)
        {
            if (rosters == null)
            {
                throw new ArgumentNullException(nameof(rosters), "Rosters must be provided.");
            }

            Logger.LogDebug($"Updating roster mappings for players in '{MetadataResolver.TableName<PlayerTeamMapSql>()}'.");

            await DbConnection.Truncate <PlayerTeamMapSql>().ExecuteAsync();

            List <PlayerSql> players = await DbConnection.Select <PlayerSql>(p => p.Id, p => p.NflId).ExecuteAsync();

            Dictionary <string, Guid> nflIdMap = players.ToDictionary(p => p.NflId, p => p.Id);

            foreach (Roster roster in rosters)
            {
                await UpdateForRosterAsync(roster, nflIdMap);
            }
        }