private async Task GetTrips() { bool canRun = true; this.Loading = true; RaisePropertyChanged("Loading"); await Task.Run(async () => { List<Trip> trips = await TripRepository.GetTrips(); trips_all = new List<Trip.All>(); if (trips==null || trips.Count == 0) { this.Error = "Geen trips gevonden"; canRun = false; this.Loading = false; RaiseAll(); return; } var count = trips.Count; if ((trips.Count >= 10) && canRun == true) { count = 10; } for (int i = 0; i < count; i++) { Task<User.All> user= Task.FromResult<User.All>(await UsersRepository.GetUserById(trips[i].Users_ID)); Task<Bob.All> bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(trips[i].Bobs_ID)); Task<Users_Destinations> destination = Task.FromResult<Users_Destinations>(await DestinationRepository.GetDestinationById((trips[i].Destinations_ID))); Task<Party> party = Task.FromResult<Party>(await PartyRepository.GetPartyById(trips[i].Party_ID)); Trip.All newTrip = new Trip.All(); newTrip.Trip = trips[i]; newTrip.User = user.Result; newTrip.Bob = bob.Result; newTrip.Party = party.Result; newTrip.Destination = destination.Result; trips_all.Add(newTrip); } this.Trips = trips_all; canRun = false; this.Loading = false; RaiseAll(); }); }
private async void newtrip_bob(Trip data) { if (data != null || MainViewVM.CurrentTrip == null) { VindRitBobVM.Request = 1; this.BobRequests = "Momenteel " + VindRitBobVM.Request.ToString() + " aanvragen"; await UserRepository.PostPoint(); this.IsEnabledOffer = false; this.VisibleCancel = Visibility.Visible; this.VisibleOffer = Visibility.Visible; MainViewVM.CurrentTrip = data; SetStatus(data.StatusID.Value); Location location = await LocationService.GetCurrent(); Party party = Task.FromResult<Party>(await PartyRepository.GetPartyById(MainViewVM.CurrentTrip.Party_ID)).Result; Users_Destinations destination = Task.FromResult<Users_Destinations>(await DestinationRepository.GetDestinationById(MainViewVM.CurrentTrip.Destinations_ID)).Result; VindRitFilterVM.SelectedDestination = destination; this.SelectedParty = party; Response farEnough = Task.FromResult<Response>(await TripRepository.Difference((Location)this.SelectedParty.Location, location)).Result; if (farEnough.Value != null) { if (double.Parse(farEnough.Value.ToString()) < 600) { //bij het feestje ShowRoute((Location)party.Location, (Location)destination.Location); SetStatus(8); ToDestination = true; } else { ShowRoute(location, (Location)party.Location); ToDestination = false; } } trip_location(); //trip.all invullen if (MainViewVM.CurrentTrip != null) { Trip.All trips_all = new Trip.All(); User.All user = await UsersRepository.GetUserById(MainViewVM.CurrentTrip.Users_ID); Bob.All bob = await BobsRepository.GetBobById(MainViewVM.CurrentTrip.Bobs_ID); Trip.All newTrip = new Trip.All(); newTrip.Trip = MainViewVM.CurrentTrip; newTrip.Party = party; newTrip.User = user; newTrip.Bob = bob; newTrip.Destination = destination; this.CurrentTrip = newTrip; } RaiseAll(); } }
//Methods private async Task GetCurrentTrip() { this.Loading = true; RaisePropertyChanged("Loading"); await Task.Run(async () => { Trip currenttrip = Task.FromResult<Trip>(await TripRepository.GetCurrentTrip()).Result; if (currenttrip != null) { if (currenttrip.Active == true) { Trip.All trips_all = new Trip.All(); User.All user = await UsersRepository.GetUserById(currenttrip.Users_ID); Bob.All bob = await BobsRepository.GetBobById(currenttrip.Bobs_ID); Users_Destinations destination = await DestinationRepository.GetDestinationById((currenttrip.Destinations_ID)); Party party = await PartyRepository.GetPartyById(currenttrip.Party_ID); Trip.All newTrip = new Trip.All(); newTrip.Trip = currenttrip; newTrip.Party = party; newTrip.User = user; newTrip.Bob = bob; newTrip.Destination = destination; MoveCar(newTrip.Trip.Status_Name); this.CurrentTrip = newTrip; } else { this.CurrentTrip = null; //geen current trip nu } } RaiseAll(); }); }