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();

            }

        }
        public static async Task<Response> PostTrip(Trip trip)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(URL.BASE);

                    var newObject = JsonConvert.SerializeObject(trip);

                    HttpResponseMessage result = await client.PostAsync(URL.TRIPS, new StringContent(newObject, Encoding.UTF8, "application/json"));
                    string json = await result.Content.ReadAsStringAsync();
                    Response data = JsonConvert.DeserializeObject<Response>(json);

                    return data;
                }
            }
            catch (JsonException jex)
            {
                return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false };
              
            }
            catch (Exception ex)
            {
                return new Response() { Error = ex.Message.ToString(), Success = false };
               
            }
        }
        private object GetTripObject()
        {
            try
            {
                Bob selectedBob = VindRitVM.SelectedBob.Bob;
                Party SelectedParty = VindRitVM.SelectedParty;
                Users_Destinations SelectedDestination = VindRitFilterVM.SelectedDestination;
                List<Friend.All> selectedFriends = VindRitFilterVM.SelectedFriends;
                BobsType type = VindRitFilterVM.SelectedBobsType;
                DateTime? minDate = VindRitFilterVM.SelectedMinDate;
                int? rating = VindRitFilterVM.SelectedRating;

                if (SelectedDestination == null || selectedBob == null || SelectedParty == null || type == null)
                {

                    //trip afronden
                    TripDone();


                    return null;
                }

                //destinations edit

                Trip trip = new Trip()
                {
                    Bobs_ID = selectedBob.ID.Value,
                    Party_ID = SelectedParty.ID,
                    Friends = JsonConvert.SerializeObject(selectedFriends),
                    Destinations_ID = SelectedDestination.Destinations_ID
                };

                return trip;

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message.ToString());
                return null;
                //return null;
            }

        }
        private void StartTrip(Trip currentTrip)
        {
            if (currentTrip != null)
            {
                MainViewVM.CurrentTrip = currentTrip;
                //update very minuten location for trip
                Messenger.Default.Send<NavigateTo>(new NavigateTo()
                {
                    Name = "trip_location"
                });


            }
        }
        //by user
        //wanneer bob accepteer, wordt door gebruiker die aanvraagd aangemaakt
        private async void MakeTrip(Trip trip, int bobID)
        {
            Response res = Task.FromResult<Response>(await TripRepository.PostTrip(trip)).Result;

            if (res.Success == true)
            {
                VindRitVM.StatusID = 1;
                Location location = await LocationService.GetCurrent();
                Trips_Locations tripL = new Trips_Locations()
                {
                    Trips_ID = res.NewID.Value,
                    Location = JsonConvert.SerializeObject(location),
                    Statuses_ID = VindRitVM.StatusID
                };

                Response okTripL = await TripRepository.PostLocation(tripL);


                Trip currentTrip = Task.FromResult<Trip>(await TripRepository.GetCurrentTrip()).Result;


                Bob.All bob = VindRitVM.SelectedBob;
                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From = MainViewVM.USER.ID,//from user
                    To = bob.User.ID,//to bob
                    Status = true,
                    Object = currentTrip
                };


                MainViewVM.socket.Emit("trip_START:send", JsonConvert.SerializeObject(socketSendToBob)); //bob
                StartTrip(currentTrip); //user
                TripSave(currentTrip);


                MakeChatroom(bobID);

            }
        }
        private async void TripDone()
        {
            var definition = new { ID = -1, UserID = -1 };
            var data = JsonConvert.SerializeObject(definition);
            var data2 = JsonConvert.SerializeObject(new Trip() { ID = -1 });


            bool ok_chatroom = Task.FromResult<bool>(await Localdata.save("chatroom.json", data)).Result;
            bool ok_trip = Task.FromResult<bool>(await Localdata.save("trip.json", data2)).Result;


            //alles op null zetten, van start
            VindRitFilterVM.SelectedDestination = new Users_Destinations();
            MainViewVM.ChatRoom = null;
            VindRitChatVM.ID = null;
            VindRitVM.SelectedParty = null;
            VindRitVM.SelectedBob = null;
            VindRitVM.SelectedUser = null;
            VindRitVM.BobAccepted = false;
            VindRitVM.StatusID = 0;

            MainViewVM.CurrentTrip = null;

            Toast.TileClear();



            Frame rootFrame = MainViewVM.MainFrame as Frame;

            if (MainViewVM.USER.IsBob == true)
            {

                Messenger.Default.Send<NavigateTo>(new NavigateTo()
                {
                    Name = "loaded",
                    View = typeof(VindRitBob)

                });
            }
            else
            {
                Messenger.Default.Send<NavigateTo>(new NavigateTo()
                {
                    Name = "loaded",
                    View = typeof(VindRit)
                });
            }


        }
        private async void TripSave(Trip trip)
        {
            if (trip != null)
            {
                await UserRepository.PostPoint();
                var data = JsonConvert.SerializeObject(trip);

                bool ok = Task.FromResult<bool>(await Localdata.save("trip.json", data)).Result;


                Messenger.Default.Send<NavigateTo>(new NavigateTo()
                {
                    Name = "newtrip_bob",
                    Data = trip
                });
            }

        }