public static async Task <FootballMatchdayResults> GetFootballResultsForSeason(string league, int season) { string matchdayXmlString = await getXml($"https://www.openligadb.de/api/getmatchdata/{league}/{season}"); FootballMatchdayResults footballMatchdayResults = getFootballResults(matchdayXmlString); return(footballMatchdayResults); }
public static async Task <FootballMatchdayResults> GetFootballResultsForMatchday(string league, int matchday, int season) // Season 2017/2018 --> season = 2017 { string matchdayXmlString = await GetXml($"https://www.openligadb.de/api/getmatchdata/{league}/{season}/{matchday}"); FootballMatchdayResults footballMatchdayResults = GetFootballResults(matchdayXmlString); return(footballMatchdayResults); }
public static async Task <FootballMatchdayResults> GetFootballMatchdayResults(string league) { string matchdayXmlString = await GetXml($"https://www.openligadb.de/api/getmatchdata/{league}"); FootballMatchdayResults footballMatchdayResults = GetFootballResults(matchdayXmlString); return(footballMatchdayResults); }
private static FootballMatchdayResults getFootballResults(string xmlString) { FootballMatchdayResults footballMatchdayResults = new FootballMatchdayResults(); XDocument xDocument = XDocument.Parse(xmlString); XNamespace xNamespace = "http://schemas.datacontract.org/2004/07/OLDB.Spa.Models.Api"; foreach (XElement matchElement in xDocument.Descendants(xNamespace + "Match")) { Match match = new Match(); IEnumerable <XElement> goalElements = matchElement.Element(xNamespace + "Goals")?.Elements(xNamespace + "Goal"); if (goalElements != null) { foreach (XElement goalElement in goalElements) { Goal goal = new Goal { GoalGetterId = int.Parse(goalElement.Element(xNamespace + "GoalGetterID")?.Value), GoalGetterName = goalElement.Element(xNamespace + "GoalGetterName")?.Value, IsOvertime = bool.Parse(goalElement.Element(xNamespace + "IsOvertime")?.Value), IsOwnGoal = bool.Parse(goalElement.Element(xNamespace + "IsOwnGoal")?.Value), IsPenalty = bool.Parse(goalElement.Element(xNamespace + "IsPenalty")?.Value), MatchMinute = goalElement.Element(xNamespace + "MatchMinute")?.Value, ScoreTeam1 = int.Parse(goalElement.Element(xNamespace + "ScoreTeam1")?.Value), ScoreTeam2 = int.Parse(goalElement.Element(xNamespace + "ScoreTeam2")?.Value) }; match.Goals.Add(goal); } } Group group = new Group { GroupId = int.Parse(matchElement.Element(xNamespace + "Group")?.Element(xNamespace + "GroupID")?.Value), GroupName = matchElement.Element(xNamespace + "Group")?.Element(xNamespace + "GroupName")?.Value, GroupOrderId = int.Parse(matchElement.Element(xNamespace + "Group")?.Element(xNamespace + "GroupOrderID")?.Value) }; match.Group = group; match.LeagueId = int.Parse(matchElement.Element(xNamespace + "LeagueId")?.Value); match.LeagueName = matchElement.Element(xNamespace + "LeagueName")?.Value; Location location = new Location { LocationCity = matchElement.Element(xNamespace + "Location")?.Element(xNamespace + "LocationCity")?.Value, LocationId = matchElement.Element(xNamespace + "Location")?.Element(xNamespace + "LocationID")?.Value, LocationStadion = matchElement.Element(xNamespace + "Location")?.Element(xNamespace + "LocationStadium")?.Value }; match.Location = location; match.MatchDateTime = DateTime.Parse(matchElement.Element(xNamespace + "MatchDateTime")?.Value); match.MatchId = int.Parse(matchElement.Element(xNamespace + "MatchID")?.Value); match.MatchIsFinished = bool.Parse(matchElement.Element(xNamespace + "MatchIsFinished")?.Value); IEnumerable <XElement> matchResultElements = matchElement.Element(xNamespace + "MatchResults")?.Elements(xNamespace + "MatchResult"); if (matchResultElements != null) { foreach (XElement matchResultElement in matchResultElements) { MatchResult matchResult = new MatchResult { GoalsTeamOne = int.Parse(matchResultElement.Element(xNamespace + "PointsTeam1")?.Value), GoalsTeamTwo = int.Parse(matchResultElement.Element(xNamespace + "PointsTeam2")?.Value), ResultDescription = matchResultElement.Element(xNamespace + "ResultDescription")?.Value, ResultId = int.Parse(matchResultElement.Element(xNamespace + "ResultID")?.Value), ResultName = matchResultElement.Element(xNamespace + "ResultName")?.Value, ResultOrderId = int.Parse(matchResultElement.Element(xNamespace + "ResultOrderID")?.Value) }; match.MatchResults.Add(matchResult); } } match.NumberOfViewers = matchElement.Element(xNamespace + "NumberOfViewers")?.Value; Team teamOne = new Team { TeamIconUrl = matchElement.Element(xNamespace + "Team1")?.Element(xNamespace + "TeamIconUrl")?.Value, TeamId = int.Parse(matchElement.Element(xNamespace + "Team1")?.Element(xNamespace + "TeamId")?.Value), TeamName = matchElement.Element(xNamespace + "Team1")?.Element(xNamespace + "TeamName")?.Value }; match.TeamOne = teamOne; Team teamTwo = new Team { TeamIconUrl = matchElement.Element(xNamespace + "Team2")?.Element(xNamespace + "TeamIconUrl")?.Value, TeamId = int.Parse(matchElement.Element(xNamespace + "Team2")?.Element(xNamespace + "TeamId")?.Value), TeamName = matchElement.Element(xNamespace + "Team2")?.Element(xNamespace + "TeamName")?.Value }; match.TeamTwo = teamTwo; footballMatchdayResults.Matches.Add(match); } return(footballMatchdayResults); }