Exemplo n.º 1
0
        public override void Run()
        {
            var config = GetConfig();

            var context = new BasketballDataContext(config);

            // UPDATE ODDS FOR GAMES STARTING IN NEXT 24 HOURS
            var targetedApiBasketballLeagueSeasonInfos = context.Games.Where(x => x.LeagueSeason.IsActive)
                                                         .Select(x => new { x.LeagueSeason.ApiBasketballLeagueId, x.LeagueSeason.ApiBasketballSeasonKey })
                                                         .Distinct()
                                                         .ToList();

            if (targetedApiBasketballLeagueSeasonInfos != null && targetedApiBasketballLeagueSeasonInfos.Count > 0)
            {
                var bookmakersDict = context.Bookmakers.ToDictionary(x => x.ApiBasketballBookmakerId, y => y.BookmakerId);
                var betTypesDict   = context.BetTypes.ToDictionary(x => x.ApiBasketballBetTypeId, y => y.BetTypeId);

                for (int i = 0; i < targetedApiBasketballLeagueSeasonInfos.Count; i++)
                {
                    var leagueSeasonInfo = targetedApiBasketballLeagueSeasonInfos[i];
                    var oddsProcessor    = new OddsProcessor(leagueSeasonInfo.ApiBasketballLeagueId, leagueSeasonInfo.ApiBasketballSeasonKey, betTypesDict, bookmakersDict);
                    oddsProcessor.Run(context);
                    context.SaveChanges();

                    if (i % 10 == 9)
                    {
                        context.Dispose();
                        context = new BasketballDataContext(config);
                    }
                }
            }

            context.Dispose();
        }
Exemplo n.º 2
0
        public override void Run()
        {
            var config = GetConfig();

            var context = new BasketballDataContext(config);

            var activeLeagueSeasons = context.LeagueSeasons.Where(x => x.IsActive).ToList();

            if (activeLeagueSeasons != null && activeLeagueSeasons.Count > 0)
            {
                var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);
                var statusDict    = context.RefGameStatuses
                                    .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode))
                                    .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId);
                for (int i = 0; i < activeLeagueSeasons.Count; i++)
                {
                    var leagueSeason = activeLeagueSeasons[i];

                    var gamesProcessor = new GamesProcessor(leagueSeason.ApiBasketballLeagueId, leagueSeason.ApiBasketballSeasonKey, countriesDict, statusDict);
                    gamesProcessor.Run(context);
                    context.SaveChanges();

                    if (i % 10 == 9)
                    {
                        context.Dispose();
                        context = new BasketballDataContext(config);
                    }
                }
            }
            context.Dispose();
        }
Exemplo n.º 3
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.CountriesFeed.GetFeedUrl();
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.CountriesFeed.FromJson(rawJson);

            var orderedCountries = feed.Countries
                                   .OrderBy(x => x.Code)
                                   .ToList();

            var existingCountries = dbContext.Countries.ToDictionary(x => x.CountryAbbr ?? "(null)");

            foreach (var country in orderedCountries)
            {
                if (!existingCountries.ContainsKey(country.Code ?? "(null)"))
                {
                    var dbCountry = new Country
                    {
                        CountryName            = country.Name,
                        CountryAbbr            = country.Code,
                        FlagUrl                = country.Flag?.ToString(),
                        ApiBasketballCountryId = country.Id
                    };
                    existingCountries.Add(country.Code, dbCountry);
                    dbContext.Countries.Add(dbCountry);
                }
            }
        }
Exemplo n.º 4
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.TeamsFeed.GetFeedUrl(this.apiBasketballLeagueId, this.apiBasketballSeasonKey);
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.TeamsFeed.FromJson(rawJson);

            // ASSUME COUNTRY ALREADY EXISTS IN COUNTRIES API ENDPOINT
            var countriesDict = dbContext.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);

            var existingTeams = dbContext.Teams.ToDictionary(x => x.ApiBasketballTeamId, y => y);

            var apiTeams = feed.Teams.ToList();

            foreach (var apiTeam in apiTeams)
            {
                if (!existingTeams.TryGetValue(apiTeam.Id, out Team dbTeam))
                {
                    dbTeam = new Team
                    {
                        ApiBasketballTeamId = apiTeam.Id,
                        CountryId           = countriesDict[apiTeam.Country.Id],
                        IsNationalTeam      = apiTeam.IsNational,
                        TeamLogoUrl         = apiTeam.Logo,
                        TeamName            = apiTeam.Name
                    };

                    existingTeams.Add(dbTeam.ApiBasketballTeamId, dbTeam);
                    dbContext.Teams.Add(dbTeam);
                }
            }
        }
Exemplo n.º 5
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.LeaguesFeed.GetFeedUrl();
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.LeaguesFeed.FromJson(rawJson);

            // ASSUME COUNTRY ALREADY EXISTS IN COUNTRIES API ENDPOINT
            var countriesDict = dbContext.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);

            var existingLeagues = dbContext.Leagues.ToDictionary(x => x.ApiBasketballLeagueId, y => y);

            var orderedLeagues = feed.Leagues.OrderBy(x => x.Country.Code ?? string.Empty).ThenBy(y => y.Name).ToList();

            foreach (var apiLeague in orderedLeagues)
            {
                if (!existingLeagues.TryGetValue(apiLeague.Id, out League dbLeague))
                {
                    dbLeague = new League
                    {
                        ApiBasketballLeagueId = apiLeague.Id,
                        LeagueName            = apiLeague.Name,
                        LeagueLogo            = apiLeague.Logo,
                        CountryId             = countriesDict[apiLeague.Country.Id],
                        LeagueType            = apiLeague.Type,
                        LeagueSeasons         = new List <LeagueSeason>()
                    };

                    existingLeagues.Add(dbLeague.ApiBasketballLeagueId, dbLeague);
                    dbContext.Leagues.Add(dbLeague);
                }

                var dbLeagueSeasons  = dbContext.LeagueSeasons.Where(x => x.League.ApiBasketballLeagueId == apiLeague.Id).ToDictionary(x => x.ApiBasketballSeasonKey);
                var leagueSeasons    = dbLeague.LeagueSeasons ?? new List <LeagueSeason>();
                var apiLeagueSeasons = apiLeague.Seasons.OrderBy(x => x.Start).ToList();

                foreach (var apiSeason in apiLeagueSeasons)
                {
                    if (!dbLeagueSeasons.ContainsKey(apiSeason.Season))
                    {
                        var dbLeagueSeason = new LeagueSeason
                        {
                            ApiBasketballSeasonKey = apiSeason.Season,
                            SeasonStartUtc         = apiSeason.Start.UtcDateTime,
                            SeasonEndUtc           = apiSeason.End.UtcDateTime,
                            ApiBasketballLeagueId  = apiLeague.Id
                        };
                        dbLeague.LeagueSeasons.Add(dbLeagueSeason);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override void Run()
        {
            var config = GetConfig();

            using (var context = new BasketballDataContext(config))
            {
                // ASSUME ALL GAMES ARE IN DB FROM DAILY TASK

                // UPDATE RESULTS FOR LIVE/RECENTLY FINAL GAMES
                // SELECT LEAGUE SEASONS WHERE
                // 1) A GAME HAS STARTED SINCE THE LAST UNIVERSAL GAME HAS GONE FINAL (PICKUP GAMES AFTER PERIOD WITHOUT RUNNING)
                // 2) A GAME IS LIVE
                // 3) THE GAME WILL START IN THE NEXT 4 HOURS
                DateTime lastFinalGameStart = context.Games.Where(x => liveOrFinalGameStatuses.Contains(x.FullGameStatusId)).Max(x => x.GameTimeUtc);
                var      targetedApiBasketballLeagueSeasonInfos = context.Games.Where(x => x.LeagueSeason.IsActive &&
                                                                                      x.GameTimeUtc > lastFinalGameStart &&
                                                                                      liveOrPregameGameStatuses.Contains(x.FullGameStatusId) &&
                                                                                      x.GameTimeUtc <= DateTime.UtcNow.AddHours(4))
                                                                  .Select(x => new { x.LeagueSeason.ApiBasketballLeagueId, x.LeagueSeason.ApiBasketballSeasonKey })
                                                                  .Distinct()
                                                                  .ToList();

                if (targetedApiBasketballLeagueSeasonInfos != null && targetedApiBasketballLeagueSeasonInfos.Count > 0)
                {
                    var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);
                    var statusDict    = context.RefGameStatuses
                                        .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode))
                                        .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId);

                    foreach (var leagueSeasonInfo in targetedApiBasketballLeagueSeasonInfos)
                    {
                        var gamesProcessor = new GamesProcessor(leagueSeasonInfo.ApiBasketballLeagueId, leagueSeasonInfo.ApiBasketballSeasonKey, countriesDict, statusDict);
                        gamesProcessor.Run(context);
                        context.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.BetTypesFeed.GetFeedUrl();
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.BetTypesFeed.FromJson(rawJson);

            var existingBookmakers = dbContext.BetTypes.ToDictionary(x => x.ApiBasketballBetTypeId, y => y);
            var apiBetTypes        = feed.BetTypes.OrderBy(x => x.Id).ToList();

            foreach (var apiBetType in apiBetTypes)
            {
                if (!existingBookmakers.ContainsKey(apiBetType.Id))
                {
                    var dbBetType = new BetType
                    {
                        BetTypeName            = apiBetType.Name,
                        ApiBasketballBetTypeId = apiBetType.Id
                    };
                    existingBookmakers.Add(dbBetType.ApiBasketballBetTypeId, dbBetType);
                    dbContext.BetTypes.Add(dbBetType);
                    dbContext.SaveChanges();                     // NORMALLY DON'T SAVE IN PROCESSORS; ORDER OF BETTYPES IS BASED ON BET FREQUENCY, SO TRY TO PRESERVE ORDER FROM API
                }
            }
        }
Exemplo n.º 8
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.BookmakersFeed.GetFeedUrl();
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.BookmakersFeed.FromJson(rawJson);

            var existingBookmakers = dbContext.Bookmakers.ToDictionary(x => x.ApiBasketballBookmakerId, y => y);
            var apiBookmakers      = feed.Bookmakers.ToList();

            foreach (var apiBookmaker in apiBookmakers)
            {
                if (!existingBookmakers.ContainsKey(apiBookmaker.Id))
                {
                    var dbBookmaker = new Bookmaker
                    {
                        BookmakerName            = apiBookmaker.Name,
                        ApiBasketballBookmakerId = apiBookmaker.Id
                    };
                    existingBookmakers.Add(dbBookmaker.ApiBasketballBookmakerId, dbBookmaker);
                    dbContext.Bookmakers.Add(dbBookmaker);
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 9
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.GamesFeed.GetFeedUrl(this.apiBasketballLeagueId, this.apiBasketballSeasonKey);
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.GamesFeed.FromJson(rawJson);

            if (feed != null)
            {
                int leagueSeasonId = dbContext.LeagueSeasons.First(x => x.ApiBasketballLeagueId == this.apiBasketballLeagueId && x.ApiBasketballSeasonKey == this.apiBasketballSeasonKey).LeagueSeasonId;

                var existingGames = dbContext.Games.ToDictionary(x => x.ApiBasketballGameId, y => y);
                var apiGames      = feed.Games.OrderBy(x => x.Date).ThenBy(y => y.Id).ToList();

                var dbTeamIdsDict = dbContext.Teams.ToDictionary(x => x.ApiBasketballTeamId, y => y.TeamId);
                var apiTeams      = feed.Games.SelectMany(x => new[] { x.Teams.Away, x.Teams.Home })
                                    .Where(x => x.Id.HasValue)
                                    .Distinct(new Feeds.GamesFeed.ApiTeam.ApiTeamComparer())
                                    .ToList();
                var  apiMissingTeams = apiTeams.Where(x => !dbTeamIdsDict.ContainsKey(x.Id.Value)).ToList();
                bool hasMissingTeams = apiMissingTeams != null && apiMissingTeams.Count > 0;
                foreach (var apiMissingTeam in apiMissingTeams)
                {
                    var dbTeam = new Team
                    {
                        ApiBasketballTeamId = apiMissingTeam.Id.Value,
                        CountryId           = this.countriesDict[Country.ApiBasketballWorldCountryId],
                        TeamName            = apiMissingTeam.Name,
                        TeamLogoUrl         = apiMissingTeam.Logo
                    };
                    dbContext.Teams.Add(dbTeam);
                }
                if (hasMissingTeams)
                {
                    dbContext.SaveChanges();
                    dbTeamIdsDict = dbContext.Teams.ToDictionary(x => x.ApiBasketballTeamId, y => y.TeamId);
                }


                foreach (var apiGame in apiGames)
                {
                    if (apiGame?.Teams?.Home?.Id != null && apiGame.Teams.Away?.Id != null)
                    {
                        FullGameStatus apiStatus = string.IsNullOrEmpty(apiGame.Status?.Short) ? FullGameStatus.Unknown : statusDict[apiGame.Status.Short];
                        if (!existingGames.TryGetValue(apiGame.Id, out Game dbGame))
                        {
                            dbGame = new Game
                            {
                                ApiBasketballGameId = apiGame.Id,
                                AwayTeamId          = dbTeamIdsDict[apiGame.Teams.Away.Id.Value],
                                CountryId           = this.countriesDict[apiGame.Country.Id],
                                FullGameStatusId    = apiStatus,
                                GameTimeUtc         = apiGame.Date.UtcDateTime,
                                HomeTeamId          = dbTeamIdsDict[apiGame.Teams.Home.Id.Value],
                                LeagueSeasonId      = leagueSeasonId,
                                QtrTimeRem          = apiGame.Status?.Timer
                            };

                            if (apiGame.Scores != null)
                            {
                                SetScoreValuesInDb(apiGame, dbGame);
                            }

                            existingGames.Add(apiGame.Id, dbGame);
                            dbContext.Games.Add(dbGame);
                        }
                        else if (IsApiUpdated(apiGame, dbGame, apiStatus))
                        {
                            dbGame.AwayTeamId       = dbTeamIdsDict[apiGame.Teams.Away.Id.Value];
                            dbGame.FullGameStatusId = apiStatus;
                            dbGame.GameTimeUtc      = apiGame.Date.UtcDateTime;
                            dbGame.HomeTeamId       = dbTeamIdsDict[apiGame.Teams.Home.Id.Value];
                            dbGame.QtrTimeRem       = apiGame.Status?.Timer;

                            if (apiGame.Scores != null)
                            {
                                SetScoreValuesInDb(apiGame, dbGame);
                            }
                        }
                    }
                }
            }
        }
        public override void Run()
        {
            var config = GetConfig();

            using (var context = new BasketballDataContext(config))
            {
                context.Countries.Add(
                    new Country
                {
                    ApiBasketballCountryId = 0,
                    CountryAbbr            = "XX",
                    CountryName            = "World",
                    FlagUrl = null
                });

                context.RefGameStatuses.AddRange(new List <RefGameStatus>
                {
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.NotStarted, FullGameStatusName = "Not Started", GameStatusId = GameStatus.Pregame, GameStatusName = "Pregame", ApiBasketballStatusCode = "NS"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_Q1, FullGameStatusName = "Live - Q1", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q1"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_Q2, FullGameStatusName = "Live - Q2", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q2"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_Q3, FullGameStatusName = "Live - Q3", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q3"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_Q4, FullGameStatusName = "Live - Q4", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "Q4"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_OT, FullGameStatusName = "Live - OT", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "OT"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_BK, FullGameStatusName = "Live - Break", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "BT"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Live_HT, FullGameStatusName = "Live - Halftime", GameStatusId = GameStatus.Live, GameStatusName = "Live", ApiBasketballStatusCode = "HT"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Final, FullGameStatusName = "Final", GameStatusId = GameStatus.Final, GameStatusName = "Final", ApiBasketballStatusCode = "FT"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.FinalWithOT, FullGameStatusName = "Final (OT)", GameStatusId = GameStatus.Final, GameStatusName = "Final", ApiBasketballStatusCode = "AOT"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Postponed, FullGameStatusName = "Postponed", GameStatusId = GameStatus.Postponed, GameStatusName = "Postponed", ApiBasketballStatusCode = "POST"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Cancelled, FullGameStatusName = "Cancelled", GameStatusId = GameStatus.Cancelled, GameStatusName = "Cancelled", ApiBasketballStatusCode = "CANC"
                    },
                    new RefGameStatus {
                        FullGameStatusId = FullGameStatus.Unknown, FullGameStatusName = "Unknown", GameStatusId = GameStatus.Unknown, GameStatusName = "Unknown", ApiBasketballStatusCode = null
                    }
                });
                context.SaveChanges();

                var bookmakersProcessor = new BookmakersProcessor();
                Console.WriteLine("START BOOKMAKERS");
                bookmakersProcessor.Run(context);
                Console.WriteLine("SAVE BOOKMAKERS");
                context.SaveChanges();
                Console.WriteLine("END BOOKMAKERS");

                var betTypesProcessor = new BetTypesProcessor();
                Console.WriteLine("START BET TYPES");
                betTypesProcessor.Run(context);
                Console.WriteLine("SAVE BET TYPES");
                context.SaveChanges();
                Console.WriteLine("END BET TYPES");

                var countriesProcessor = new CountriesProcessor();
                Console.WriteLine("START COUNTRIES");
                countriesProcessor.Run(context);
                Console.WriteLine("SAVE COUNTRIES");
                context.SaveChanges();
                Console.WriteLine("END COUNTRIES");

                var leaguesProcessor = new LeaguesProcessor();
                Console.WriteLine("START LEAGUES");
                leaguesProcessor.Run(context);
                Console.WriteLine("SAVE LEAGUES");
                context.SaveChanges();
                Console.WriteLine("END LEAGUES");

                var leagueSeasons = context.LeagueSeasons
                                    .OrderBy(x => x.LeagueSeasonId)
                                    .Select(y => new { y.ApiBasketballLeagueId, y.ApiBasketballSeasonKey })
                                    .ToList();

                foreach (var leagueSeason in leagueSeasons)
                {
                    int    leagueId       = leagueSeason.ApiBasketballLeagueId;
                    string seasonKey      = leagueSeason.ApiBasketballSeasonKey;
                    var    teamsProcessor = new TeamsProcessor(leagueId, seasonKey);
                    Console.WriteLine($"START TEAMS - {leagueId} {seasonKey}");
                    teamsProcessor.Run(context);
                    Console.WriteLine($"SAVE TEAMS - {leagueId} {seasonKey}");
                    context.SaveChanges();
                    Console.WriteLine($"END TEAMS - {leagueId} {seasonKey}");
                }

                var countriesDict = context.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);
                var teamsDict     = context.Teams.ToDictionary(x => x.ApiBasketballTeamId, y => y.TeamId);
                var statusDict    = context.RefGameStatuses
                                    .Where(x => !string.IsNullOrEmpty(x.ApiBasketballStatusCode))
                                    .ToDictionary(x => x.ApiBasketballStatusCode, y => y.FullGameStatusId);
                foreach (var leagueSeason in leagueSeasons)
                {
                    int    leagueId       = leagueSeason.ApiBasketballLeagueId;
                    string seasonKey      = leagueSeason.ApiBasketballSeasonKey;
                    var    gamesProcessor = new GamesProcessor(leagueId, seasonKey, countriesDict, statusDict);
                    Console.WriteLine($"START GAMES - {leagueId} {seasonKey}");
                    gamesProcessor.Run(context);
                    Console.WriteLine($"SAVE GAMES - {leagueId} {seasonKey}");
                    context.SaveChanges();
                    Console.WriteLine($"END GAMES - {leagueId} {seasonKey}");
                }

                var bookmakersDict = context.Bookmakers.ToDictionary(x => x.ApiBasketballBookmakerId, y => y.BookmakerId);
                var betTypesDict   = context.BetTypes.ToDictionary(x => x.ApiBasketballBetTypeId, y => y.BetTypeId);

                var liveAndUpcomingGameStatuses = context.RefGameStatuses
                                                  .Where(x => x.GameStatusId == GameStatus.Pregame || x.GameStatusId == GameStatus.Live)
                                                  .Select(x => x.FullGameStatusId)
                                                  .ToList();

                foreach (var leagueSeason in leagueSeasons)
                {
                    int    leagueId      = leagueSeason.ApiBasketballLeagueId;
                    string seasonKey     = leagueSeason.ApiBasketballSeasonKey;
                    var    oddsProcessor = new OddsProcessor(leagueId, seasonKey, betTypesDict, bookmakersDict);
                    Console.WriteLine($"START ODDS - {leagueId} {seasonKey}");
                    oddsProcessor.Run(context);
                    Console.WriteLine($"SAVE ODDS - {leagueId} {seasonKey}");
                    context.SaveChanges();
                    Console.WriteLine($"END ODDS - {leagueId} {seasonKey}");
                }
            }
        }
Exemplo n.º 11
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.OddsFeed.GetFeedUrl(this.apiBasketballLeagueId, this.apiBasketballSeasonKey);
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);

            if (!string.IsNullOrEmpty(rawJson))
            {
                var feed = Feeds.OddsFeed.FromJson(rawJson);

                int leagueSeasonId = dbContext.LeagueSeasons.First(x => x.ApiBasketballLeagueId == this.apiBasketballLeagueId && x.ApiBasketballSeasonKey == this.apiBasketballSeasonKey).LeagueSeasonId;
                var gameDict       = dbContext.Games.Where(x => x.LeagueSeasonId == leagueSeasonId).ToDictionary(x => x.ApiBasketballGameId, y => y.GameId);

                var apiOddsGames = feed.OddsGames.ToList();
                foreach (var apiOddsGame in apiOddsGames)
                {
                    if (gameDict.TryGetValue(apiOddsGame.Game.Id, out int gameId))
                    {
                        var allGameLines = dbContext.BetLines.Where(x => x.GameId == gameId).ToList();
                        foreach (var apiBookmaker in apiOddsGame.Bookmakers)
                        {
                            int bookmakerId = this.bookmakersDict[apiBookmaker.BookmakerId];
                            foreach (var apiBetType in apiBookmaker.BetTypes)
                            {
                                int betTypeId = this.betTypesDict[apiBetType.BetTypeId];
                                foreach (var apiBetLine in apiBetType.BetLines)
                                {
                                    decimal betLine  = apiBetLine.Line_Decimal;
                                    decimal?betValue = null;
                                    string  betName  = apiBetLine.BetName.ToUpperInvariant();
                                    if (betName.StartsWith("OVER ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("UNDER ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("HOME ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("AWAY ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("DRAW ", StringComparison.InvariantCulture))
                                    {
                                        string[] arrBetName = betName.Split(' ');
                                        betName = arrBetName[0];
                                        if (arrBetName.Length > 1)
                                        {
                                            string strBetValue = arrBetName[1];
                                            if (!string.IsNullOrEmpty(strBetValue))
                                            {
                                                betValue = decimal.Parse(strBetValue);
                                            }
                                        }
                                    }
                                    var dbBetLine = allGameLines.SingleOrDefault(x => x.GameId == gameId && x.BookmakerId == bookmakerId && x.BetTypeId == betTypeId && x.BetName == betName);
                                    if (dbBetLine == null)
                                    {
                                        dbBetLine = new BetLine
                                        {
                                            GameId      = gameId,
                                            BookmakerId = bookmakerId,
                                            BetTypeId   = betTypeId,
                                            BetName     = betName,
                                            BetValue    = betValue,
                                            Line        = betLine
                                        };
                                        allGameLines.Add(dbBetLine);
                                        dbContext.BetLines.Add(dbBetLine);
                                    }
                                    else if (dbBetLine.BetValue != betValue || dbBetLine.Line != betLine)
                                    {
                                        dbBetLine.BetValue = betValue;
                                        dbBetLine.Line     = betLine;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }