private async Task InitAsync(Film film) { IsLoading = true; if (film != null) { Film = film; Species.Clear(); foreach (var specy in film.species) { var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ?? await _dataService.GetSingleByUrl <Specie>(specy); Species.Add(currentSpecy); } Species = Species.OrderBy(item => item.name).ToObservableCollection(); Starships.Clear(); foreach (var starship in film.starships) { var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ?? await _dataService.GetSingleByUrl <Starship>(starship); Starships.Add(currentStarship); } Starships = Starships.OrderBy(item => item.name).ToObservableCollection(); Vehicles.Clear(); foreach (var vehicle in film.vehicles) { var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ?? await _dataService.GetSingleByUrl <Vehicle>(vehicle); Vehicles.Add(currentVehicle); } Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection(); People.Clear(); foreach (var character in film.characters) { var currentPeople = await _peopleRepository.GetPeopleAsync(character) ?? await _dataService.GetSingleByUrl <People>(character); People.Add(currentPeople); } People = People.OrderBy(item => item.name).ToObservableCollection(); Planets.Clear(); foreach (var planet in film.planets) { var currentPlanet = await _planetRepository.GetPlanetAsync(planet) ?? await _dataService.GetSingleByUrl <Planet>(planet); Planets.Add(currentPlanet); } Planets = Planets.OrderBy(item => item.name).ToObservableCollection(); } IsLoading = false; }
private async Task InitAsync(Specie specie) { IsLoading = true; if (specie != null) { Specie = specie; Movies.Clear(); if (specie.films.HasItems()) { foreach (var film in specie.films) { var currentFilm = await _filmRepository.GetFilmAsync(film) ?? await _dataService.GetSingleByUrl <Film>(film); Movies.Add(currentFilm); } Movies = Movies.OrderBy(item => item.episode_id).ToObservableCollection(); } People.Clear(); if (specie.people.HasItems()) { foreach (var person in specie.people) { var currentPerson = await _peopleRepository.GetPeopleAsync(person) ?? await _dataService.GetSingleByUrl <People>(person); People.Add(currentPerson); } People = People.OrderBy(item => item.name).ToObservableCollection(); } Starships.Clear(); if (specie.starships.HasItems()) { foreach (var starship in specie.starships) { var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ?? await _dataService.GetSingleByUrl <Starship>(starship); Starships.Add(currentStarship); } Starships = Starships.OrderBy(item => item.name).ToObservableCollection(); } Vehicles.Clear(); if (specie.vehicles.HasItems()) { foreach (var vehicle in specie.vehicles) { var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ?? await _dataService.GetSingleByUrl <Vehicle>(vehicle); Vehicles.Add(currentVehicle); } Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection(); } if (specie.homeworld.IsNeitherNullNorEmpty()) { HomeWorld = await _planetRepository.GetPlanetAsync(Specie?.homeworld) ?? await _dataService.GetSingleByUrl <Planet>(Specie?.homeworld); } } IsLoading = false; }
private async Task InitAsync(People person) { IsLoading = true; if (person != null) { Person = person; Species.Clear(); if (person.species != null && person.species.Count() > 1) { foreach (var specy in person.species) { var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ?? await _dataService.GetSingleByUrl <Specie>(specy); Species.Add(currentSpecy); } Species = Species.OrderBy(item => item.name).ToObservableCollection(); } else { var specy = person.species.FirstOrDefault(); if (specy != null) { CurrentSpecie = await _speciesRepository.GetSpecieAsync(specy) ?? await _dataService.GetSingleByUrl <Specie>(specy); } } Starships.Clear(); foreach (var starship in person.starships) { var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ?? await _dataService.GetSingleByUrl <Starship>(starship); Starships.Add(currentStarship); } Starships = Starships.OrderBy(item => item.name).ToObservableCollection(); Vehicles.Clear(); foreach (var vehicle in person.vehicles) { var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ?? await _dataService.GetSingleByUrl <Vehicle>(vehicle); Vehicles.Add(currentVehicle); } Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection(); var movies = new ObservableCollection <Film>(); foreach (var film in person.films) { var currentFilm = await _filmRepository.GetFilmAsync(film) ?? await _dataService.GetSingleByUrl <Film>(film); movies.Add(currentFilm); } Movies = movies.OrderBy(item => item.episode_id).ToObservableCollection(); HomeWorld = await _planetRepository.GetPlanetAsync(Person?.homeworld) ?? await _dataService.GetSingleByUrl <Planet>(Person?.homeworld); } IsLoading = false; }