async public Task GetChallenges(bool forceRefresh = false) { if (Athlete == null) { return; } if (!forceRefresh && _hasLoadedBefore) { Athlete.RefreshChallenges(); return; } if (IsBusy) { return; } using (new Busy(this)) { Athlete.RefreshChallenges(); UpcomingChallenges.Clear(); HistoricalChallenges.Clear(); ChallengeGroups.Clear(); //Load the opponents var task = AzureService.Instance.GetAllChallengesByAthlete(Athlete); await RunSafe(task); if (task.IsFaulted) { return; } // var list = new List<string>(); // foreach(var c in DataManager.Instance.Challenges.Values) // { // if(!list.Contains(c.ChallengeeAthleteId)) // list.Add(c.ChallengeeAthleteId); // // if(!list.Contains(c.ChallengerAthleteId)) // list.Add(c.ChallengerAthleteId); // // if(c.ChallengeeAthlete == null || forceRefresh) // { // await RunSafe(AzureService.Instance.GetAthleteById(c.ChallengeeAthleteId, forceRefresh)); // } // // if(c.ChallengerAthlete == null || forceRefresh) // { // await RunSafe(AzureService.Instance.GetAthleteById(c.ChallengerAthleteId, forceRefresh)); // } // } _hasLoadedBefore = true; LocalRefresh(); } }
public void LocalRefresh() { ChallengeGroups.Clear(); UpcomingChallenges.Clear(); HistoricalChallenges.Clear(); Athlete.RefreshChallenges(); SetPropertyChanged("Athlete"); Athlete.AllChallenges.Where(c => c.IsCompleted).ToList().ForEach(HistoricalChallenges.Add); Athlete.AllChallenges.Where(c => !c.IsCompleted).ToList().ForEach(UpcomingChallenges.Add); if (OnLocalRefresh != null) { OnLocalRefresh(); } if (UpcomingChallenges.Count > 0) { ChallengeGroups.Add(UpcomingChallenges); } if (HistoricalChallenges.Count > 0) { ChallengeGroups.Add(HistoricalChallenges); } if (ChallengeGroups.Count == 0) { ChallengeGroups.Add(new ChallengeCollection { Title = "You have no challenges" }); } }