public async Task Init() { var leaguesList = await _apiServiceLeagues.Get <List <Leagues> >(null); if (leaguesList.Count > 0) { LeaguesList.Clear(); foreach (var item in leaguesList) { LeaguesList.Add(item); } } }
public async Task Init() { try { if (LeaguesList.Count == 0) { var leagues = await _apiServiceLeagues.Get <List <Leagues> >(null); if (leagues.Count > 0) { foreach (var item in leagues) { LeaguesList.Add(item); } } else { await Application.Current.MainPage.DisplayAlert("Information", "We don't have leagues.", "OK"); } } if (SelectedLeague != null) { RecommendedMatch = string.Empty; var clubInLeague = await _apiServiceClubs.GetById <List <ClubsLeague> >(SelectedLeague.Id, "ClubsInLeague"); if (clubInLeague.Count > 0) { ClubsPoints.Clear(); var counter = 0; foreach (var item in clubInLeague) { var club = await _apiServiceClubs.GetById <Clubs>(item.ClubId); if (club != null) { ClubsPoints.Add(new ClubPoints { Id = club.Id, Abbreviation = club.Abbreviation, Logo = club.Logo, Name = club.Name, Points = item.Points, Position = counter + 1 }); } } var match = await _apiServiceMatches.GetById <Matches>(SelectedLeague.Id, "RecommendMatch"); if (match == null) { await Application.Current.MainPage.DisplayAlert("Information", "There is no recommended match for now. Check later.", "OK"); return; } var homeClub = await _apiServiceClubs.GetById <Clubs>(match.HomeClubId); var awayClub = await _apiServiceClubs.GetById <Clubs>(match.AwayClubId); RecommendedMatch = $"{homeClub.Name} vs {awayClub.Name} - {match.DateGame:dddd, dd MMMM yyyy} {match.GameStart}"; } else { await Application.Current.MainPage.DisplayAlert("Information", "We don't have clubs in leagues", "OK"); } } } catch (System.Exception) { await Application.Current.MainPage.DisplayAlert("Information", "Error", "OK"); return; throw; } }