private static List <LiveGame> CastToLocalModel(Sports.RootObject liveGamesJson) { var liveGames = new List <LiveGame>(); foreach (var tournament in liveGamesJson.sportItem.tournaments) { var live = tournament.events.Where(input => input.status.type == "inprogress").ToList(); foreach (var liveEvent in live) { liveGames.Add(new LiveGame { Sport = (Sport)liveEvent.sport.id, AwayTeam = liveEvent.awayTeam.name, HomeTeam = liveEvent.homeTeam.name, CustomId = liveEvent.customId, GameName = liveEvent.name, GameUrl = $"https://www.sofascore.com/da/{liveEvent.slug}/{liveEvent.customId}", Id = liveEvent.id, TournamentId = tournament.tournament.id, TournamentName = tournament.tournament.name, SetAlgorithms = new List <int>() }); } } return(liveGames); }
private static IEnumerable <LiveGame> GetLiveGames(string url, Sport sport) { using WebClient webClient = new WebClient(); var liveGamesString = webClient.DownloadString(url); var liveGamesJson = new Sports.RootObject(); try { liveGamesJson = JsonConvert.DeserializeObject <Sports.RootObject>(liveGamesString); } catch (Exception e) { return(new List <LiveGame>()); } var result = CastToLocalModel(liveGamesJson); return(result); }