public List <LeagueTableView> CreateLeagueTable(StandingsList list) { List <LeagueTableView> finalList = new List <LeagueTableView>(); foreach (var item in list.standings.Values.ElementAt(0).standing_participants) { LeagueTableView actualView = new LeagueTableView() { Rank = int.Parse(item.Value.rank), TeamName = item.Value.participant.name, MatchesPlayed = item.Value.standing_data.Find(a => a.code == "played").value, Wins = item.Value.standing_data.Find(a => a.code == "wins").value, Draws = item.Value.standing_data.Find(a => a.code == "draws").value, Losses = item.Value.standing_data.Find(a => a.code == "defeits").value, GoalsFor = item.Value.standing_data.Find(a => a.code == "goalsfor").value, GoalsAgainst = item.Value.standing_data.Find(a => a.code == "goalsagainst").value, Points = item.Value.standing_data.Find(a => a.code == "points").value, TeamId = item.Value.id, TeamParticipantFK = item.Value.participantFK }; finalList.Add(actualView); } finalList = finalList.OrderBy(o => o.Rank).ToList(); return(finalList); }
public Standings(NewStandings ns) { has_next = ns.new_entries.has_next; number = ns.new_entries.number; standings = new StandingsList(); standings.results = new List <Standing>(); foreach (var nr in ns.new_entries.results) { Standing standing = new Standing(); standing.entry = nr.entry; standing.id = nr.id; standing.player_name = nr.player_first_name + " " + nr.player_last_name; standing.entry_name = nr.entry_name; standings.results.Add(standing); } }
public List <TopScorersView> CreateTopScorersList(StandingsList list) { List <TopScorersView> finalList = new List <TopScorersView>(); foreach (var item in list.standings.Values.ElementAt(0).standing_participants) { TopScorersView actualPlayer = new TopScorersView() { Rank = int.Parse(item.Value.rank), Goals = item.Value.standing_data.Find(a => a.code == "goals").value, PlayerName = item.Value.participant.name }; finalList.Add(actualPlayer); } finalList = finalList.OrderBy(o => o.Rank).ToList(); return(finalList); }
public List <EventStatisticsView> CreateEventStatisticsList(StandingsList list) { List <EventStatisticsView> statistics = new List <EventStatisticsView>(); if (list.standings.Values.ElementAt(0).standing_participants.Count == 0) { return(null); } var homeTeam = list.standings.Values.ElementAt(0).standing_participants.ElementAt(0).Value; var awayTeam = list.standings.Values.ElementAt(0).standing_participants.ElementAt(1).Value; if (homeTeam.standing_data.Count != awayTeam.standing_data.Count) { throw new Exception("alma"); } for (int i = 0; i < homeTeam.standing_data.Count; i++) { if (homeTeam.standing_data.ElementAt(i).code != awayTeam.standing_data.ElementAt(i).code) { throw new Exception("banan"); } statistics.Add(new EventStatisticsView { HomeTeamValue = homeTeam.standing_data.ElementAt(i).value, AwayTeamValue = awayTeam.standing_data.ElementAt(i).value, Name = homeTeam.standing_data.ElementAt(i).code, ChartBase = new List <Data> { new Data { Value = homeTeam.standing_data.ElementAt(i).value }, new Data { Value = awayTeam.standing_data.ElementAt(i).value } } }); } return(statistics); }
/// <summary> /// Load the league standings /// </summary> /// <param name="country"></param> private async void SortStandings(Country country) { try { StandingsList = await repository.LoadStandings(country.competition_id); if (StandingsList != null) { string leagueCheck = ""; bool groupedLeague = false; foreach (Table team in StandingsList) { if (string.IsNullOrWhiteSpace(leagueCheck)) { leagueCheck = team.league_id; } //if teams are all from the same league if (leagueCheck == team.league_id) { groupedLeague = false; } //if there are teams from different leagues e.g. group stage of a cup else { groupedLeague = true; break; } //load the team logos foreach (Logo logo in repository.LoadLogos()) { if (team.name.ToLower() == logo.team_name.ToLower()) { team.logo = logo.logo; break; } if (team.name.Contains(logo.team_name) || $"FC {team.name}".Contains(logo.team_name) || $"{team.name} FC".Contains(logo.team_name)) { team.logo = logo.logo; } } } //if standings for a cup group then sort and group them by their group StandingsList = (groupedLeague) ? StandingsList.Where(t => t.league_id == country.league_id).ToList() : StandingsList; HighlightCurrentTeams(country); StandingsVis = (StandingsList.Count != 0) ? true : false; } GoalscorerList = await repository.LoadTopGoalscorers(country.competition_id); if (GoalscorerList != null) { var i = 0; foreach (Goalscorer goalscorer in GoalscorerList) { i++; goalscorer.rank = i.ToString(); foreach (Logo logo in repository.LoadLogos()) { if (goalscorer.team.name.ToLower() == logo.team_name.ToLower()) { goalscorer.logo = logo.logo; break; } if (goalscorer.team.name.Contains(logo.team_name) || $"FC {goalscorer.team.name}".Contains(logo.team_name) || $"{goalscorer.team.name} FC".Contains(logo.team_name)) { goalscorer.logo = logo.logo; } } } GoalscorersVis = (GoalscorerList.Count != 0) ? true : false; } //display standings tab if league standings are available and hide if not if (StandingsList?.Count != 0 || GoalscorerList?.Count != 0) { Messenger.Default.Send("leagueAvailable"); StandingsIndex = (StandingsVis) ? 0 : 1; } else { Messenger.Default.Send("leagueUnavailable"); } } catch (Exception ex) { if (ex.Message != "BadRequest") { errorHandler.CheckErrorMessage(ex); } else { Messenger.Default.Send("leagueUnavailable"); } } }