StandingsViewModel.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace FormulaOneApp.Classic.Core.ViewModels
  2. {
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Cirrious.MvvmCross.ViewModels;
  7. using ErgastAPI.Model.Standing;
  8. using ErgastAPI.Services.Standings;
  9. public class StandingsViewModel : MvxViewModel
  10. {
  11. // Services
  12. private IStandingService _standingService;
  13. // Variables
  14. private ObservableCollection<DriverStanding> _standing;
  15. public StandingsViewModel(IStandingService standingService)
  16. {
  17. _standingService = standingService;
  18. LoadStandingsAsync();
  19. }
  20. public ObservableCollection<DriverStanding> Standing
  21. {
  22. get { return _standing; }
  23. set
  24. {
  25. _standing = value;
  26. RaisePropertyChanged();
  27. }
  28. }
  29. private async Task LoadStandingsAsync()
  30. {
  31. var result = await _standingService.GetSeasonDriverStandingsCollectionAsync();
  32. Standing = new ObservableCollection<DriverStanding>();
  33. foreach (var standing in result.StandingsLists.First().DriverStandings)
  34. {
  35. Standing.Add(standing);
  36. }
  37. }
  38. }
  39. }