private void SaveFootballDataModelToDb(FootballDataModel match, ref int processedGames) { bool onlyCreated; var leagueSeason = leagueDataRepo.CreateAndSaveLeagueSeason(_startYear, leagueDataRepo.GetLaLiga()); var homeTeam = leagueDataRepo.GetFootballTeam(match.HomeTeam, leagueSeason, "FootballData"); var awayTeam = leagueDataRepo.GetFootballTeam(match.AwayTeam, leagueSeason, "FootballData"); Game matchDb = null; try { matchDb = leagueDataRepo.GetGame(homeTeam, awayTeam, match.MatchDate, leagueSeason, out onlyCreated); } catch (Exception ex) { return; } if (onlyCreated || matchDb.Result == 0) //update game record { //Console.WriteLine("Game record only created - will be processed"); matchDb.AwayTeamGoals = match.FullTimeAwayTeamGoals; matchDb.HomeTeamGoals = match.FullTimeHomeTeamGoals; if (matchDb.HomeTeamGoals > matchDb.AwayTeamGoals) { matchDb.Result = GameResult.HomeWin; } else if (matchDb.HomeTeamGoals < matchDb.AwayTeamGoals) { matchDb.Result = GameResult.AwayWin; } else { matchDb.Result = GameResult.Draw; } leagueDataRepo.UpdateGameRecord(matchDb); processedGames++; } var matchStats = leagueDataRepo.GetGameStats(matchDb.GameId, out onlyCreated); if (onlyCreated) //update game stats { matchStats.Game = matchDb; matchStats.HalfTimeHomeGoals = match.HalfTimeHomeTeamGoals; matchStats.HalfTimeAwayGoals = match.HalfTimeAwayTeamGoals; if (matchStats.HalfTimeHomeGoals > matchStats.HalfTimeAwayGoals) { matchStats.HalfTimeResult = GameResult.HomeWin; } else if (matchStats.HalfTimeHomeGoals < matchStats.HalfTimeAwayGoals) { matchStats.HalfTimeResult = GameResult.AwayWin; } else { matchStats.HalfTimeResult = GameResult.Draw; } matchStats.HomeTeamShots = match.HomeTeamShots; matchStats.AwayTeamShots = match.AwayTeamShots; matchStats.HomeTeamTargetShots = match.HomeTeamShotsOnTarget; matchStats.AwayTeamTargetShots = match.AwayTeamShotsOnTarget; matchStats.HomeTeamFouls = match.HomeTeamFouls; matchStats.AwayTeamFouls = match.AwayTeamFouls; matchStats.HomeTeamCorners = match.HomeTeamCorners; matchStats.AwayTeamCorners = match.AwayTeamCorners; matchStats.HomeTeamYCards = match.HomeTeamYellowCards; matchStats.AwayTeamYCards = match.AwayTeamYellowCards; matchStats.HomeTeamRedCards = match.HomeTeamRedCards; matchStats.AwayTeamRedCards = match.AwayTeamRedCards; matchStats.HomeTeamOffsides = match.HomeTeamOffsides; matchStats.AwayTeamOffsides = match.AwayTeamOffsides; leagueDataRepo.UpdateGameStats(matchStats); } var bookmaker = bookmakerRepo.GetBookmaker("Bet365"); var bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.B365_HomeWin; bookmakerOdd.DrawCoef = match.B365_Draw; bookmakerOdd.AwayWinCoef = match.B365_AwayWin; bookmakerOdd.Total2_5Over = match.B365_TotalMore2_5; bookmakerOdd.Total2_5Under = match.B365_TotalLess2_5; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Blue Square"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.BS_HomeWin; bookmakerOdd.DrawCoef = match.BS_Draw; bookmakerOdd.AwayWinCoef = match.BS_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Bet&Win"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.BW_HomeWin; bookmakerOdd.DrawCoef = match.BW_Draw; bookmakerOdd.AwayWinCoef = match.BW_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Gamebookers"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.GB_HomeWin; bookmakerOdd.DrawCoef = match.GB_Draw; bookmakerOdd.AwayWinCoef = match.GB_AwayWin; bookmakerOdd.Total2_5Over = match.GB_TotalMore2_5; bookmakerOdd.Total2_5Under = match.GB_TotalLess2_5; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Interwetten"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.IW_HomeWin; bookmakerOdd.DrawCoef = match.IW_Draw; bookmakerOdd.AwayWinCoef = match.IW_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Pinnacle"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.Pinnacle_HomeWin; bookmakerOdd.DrawCoef = match.Pinnacle_Draw; bookmakerOdd.AwayWinCoef = match.Pinnacle_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Sporting Odds"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.SO_HomeWin; bookmakerOdd.DrawCoef = match.SO_Draw; bookmakerOdd.AwayWinCoef = match.SO_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Sportingbet"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.SB_HomeWin; bookmakerOdd.DrawCoef = match.SB_Draw; bookmakerOdd.AwayWinCoef = match.SB_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Stan James"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.SJ_HomeWin; bookmakerOdd.DrawCoef = match.SJ_Draw; bookmakerOdd.AwayWinCoef = match.SJ_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Stanleybet"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.Stanleybet_HomeWin; bookmakerOdd.DrawCoef = match.Stanleybet_Draw; bookmakerOdd.AwayWinCoef = match.Stanleybet_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("VC"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.VC_HomeWin; bookmakerOdd.DrawCoef = match.VC_Draw; bookmakerOdd.AwayWinCoef = match.VC_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("William Hill"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.HomeWinCoef = match.WH_HomeWin; bookmakerOdd.DrawCoef = match.WH_Draw; bookmakerOdd.AwayWinCoef = match.WH_AwayWin; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Total average odds"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.Total2_5Over = match.Average_TotalMore2_5; bookmakerOdd.Total2_5Under = match.Average_TotalLess2_5; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } bookmaker = bookmakerRepo.GetBookmaker("Total maximal odds"); bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated); if (onlyCreated) //update game record { bookmakerOdd.Total2_5Over = match.Max_TotalMore2_5; bookmakerOdd.Total2_5Under = match.Max_TotalLess2_5; bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd); } }