Ejemplo n.º 1
0
        public void OnDataChange(DataSnapshot snapshot)
        {
            if (snapshot.Value != null)
            {
                RideDetails rideDetails = new RideDetails();
                rideDetails.DestinationAddress = snapshot.Child("destination_address").Value.ToString();
                rideDetails.DestinationLat     = double.Parse(snapshot.Child("destination").Child("latitude").Value.ToString());
                rideDetails.DestinationLng     = double.Parse(snapshot.Child("destination").Child("longitude").Value.ToString());

                rideDetails.PickupAddress = snapshot.Child("pickup_address").Value.ToString();
                rideDetails.PickupLat     = double.Parse(snapshot.Child("location").Child("latitude").Value.ToString());
                rideDetails.PickupLng     = double.Parse(snapshot.Child("location").Child("longitude").Value.ToString());


                rideDetails.RideId     = snapshot.Key;
                rideDetails.RiderName  = snapshot.Child("rider_name").Value.ToString();
                rideDetails.RiderPhone = snapshot.Child("rider_phone").Value.ToString();
                RideDetailsFound?.Invoke(this, new RideDetailsEventArgs {
                    RideDetails = rideDetails
                });
            }
            else
            {
                RideDetailsNotFound?.Invoke(this, new EventArgs());
            }
        }
        public void GetRideDetails(string ride_id)
        {
            DatabaseReference rideDetailsRef = Database.DefaultInstance.GetRootReference().GetChild("rideRequest/" + ride_id);

            rideDetailsRef.ObserveSingleEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                if (snapshot.GetValue <NSObject>() != NSNull.Null)
                {
                    RideDetails rideDetails        = new RideDetails();
                    rideDetails.DestinationAddress = snapshot.GetChildSnapshot("destination_address").GetValue <NSObject>().ToString();
                    rideDetails.DestinationLat     = double.Parse(snapshot.GetChildSnapshot("destination").GetChildSnapshot("latitude").GetValue <NSObject>().ToString());
                    rideDetails.DestinationLng     = double.Parse(snapshot.GetChildSnapshot("destination").GetChildSnapshot("longitude").GetValue <NSObject>().ToString());
                    rideDetails.PickupAddress      = snapshot.GetChildSnapshot("pickup_address").GetValue <NSObject>().ToString();
                    rideDetails.PickupLat          = double.Parse(snapshot.GetChildSnapshot("location").GetChildSnapshot("latitude").GetValue <NSObject>().ToString());
                    rideDetails.PickLng            = double.Parse(snapshot.GetChildSnapshot("location").GetChildSnapshot("longitude").GetValue <NSObject>().ToString());

                    rideDetails.RideId     = snapshot.Key;
                    rideDetails.RiderName  = snapshot.GetChildSnapshot("rider_name").GetValue <NSObject>().ToString();
                    rideDetails.RiderPhone = snapshot.GetChildSnapshot("rider_phone").GetValue <NSObject>().ToString();

                    RideDetailsFound?.Invoke(this, new RideDetailsEventArgs {
                        RideDetails = rideDetails
                    });
                }
                else
                {
                    RideDetailsNotFound?.Invoke(this, new EventArgs());
                }
            });
        }