public void FillExtendedAddress(ExtendedAddress extendedAddress, GmsDetailsResultItem gmsDetailsResult)
        {
            extendedAddress.BasicAddress = new Address {
            };

            if (gmsDetailsResult == null)
            {
                return;
            }

            //registrationEntry.ServiceAddress = new ExtendedAddress() { BasicAddress = new Address() };
            extendedAddress.Longitude = Convert.ToDecimal(gmsDetailsResult.Geometry.Location.Longitude);
            extendedAddress.Latitude  = Convert.ToDecimal(gmsDetailsResult.Geometry.Location.Latitude);
            string route = string.Empty;

            foreach (var component in gmsDetailsResult.AddressComponents)
            {
                if (component.Types.Contains("postal_code"))
                {
                    extendedAddress.BasicAddress.ZipCode = component.LongName;
                }
                if (component.Types.Contains("country"))
                {
                    extendedAddress.BasicAddress.Country = component.LongName;
                }
                if (component.Types.Contains("administrative_area_level_1"))
                {
                    extendedAddress.BasicAddress.StateProv = component.ShortName;
                }
                if (component.Types.Contains("locality"))
                {
                    extendedAddress.BasicAddress.City = component.LongName;
                }
                if (component.Types.Contains("route"))
                {
                    route = component.ShortName;
                }
                if (component.Types.Contains("neighborhood"))
                {
                    extendedAddress.BasicAddress.Line3 = component.LongName;
                }
                if (component.Types.Contains("street_number"))
                {
                    if (!string.IsNullOrEmpty(component.ShortName))
                    {
                        extendedAddress.BasicAddress.Line1 = component.ShortName;
                    }
                    else if (!string.IsNullOrEmpty(component.LongName))
                    {
                        extendedAddress.BasicAddress.Line1 = component.LongName;
                    }
                }
            }

            if (!string.IsNullOrEmpty(route) && !string.IsNullOrEmpty(extendedAddress.BasicAddress.Line1))
            {
                extendedAddress.BasicAddress.Line1 += " ";
                extendedAddress.BasicAddress.Line1 += route;
            }
        }
        public ExtendedAddress GetExtendedAddress(GmsDetailsResultItem gmsDetailsResult)
        {
            var extendedAddress = new ExtendedAddress();

            FillExtendedAddress(extendedAddress, gmsDetailsResult);
            return(extendedAddress);
        }
 public string GetStreetAddress(GmsDetailsResultItem gmsDetailsResult)
 {
     if (gmsDetailsResult != null && gmsDetailsResult.AddressComponents != null)
     {
         foreach (var component in gmsDetailsResult.AddressComponents)
         {
             if (component.Types.Contains("street_number"))
             {
                 if (!string.IsNullOrEmpty(component.ShortName))
                 {
                     return(component.ShortName);
                 }
                 else if (!string.IsNullOrEmpty(component.LongName))
                 {
                     return(component.LongName);
                 }
             }
         }
     }
     return(string.Empty);
 }
Beispiel #4
0
        async void ButtonNext_Clicked(object sender, System.EventArgs e)
        {
            (sender as VisualElement).IsEnabled = false;
            this.IsBusy = true;
            try
            {
                var state = string.Empty;
                if (stateEntry.SelectedIndex >= 0)
                {
                    state = stateEntry.Items[stateEntry.SelectedIndex];
                    state = mStates[state];
                }

                string Address = zipcodeEntry.Text + " US";

                GmsDetailsResultItem gmsDetailsResult = await Task.Run(() => { return(mAddressFacade.GetGmsDetails(Address)); });

                if (gmsDetailsResult != null)
                {
                    ExtendedAddress serviceAddress = new ExtendedAddress()
                    {
                        BasicAddress = new ColonyConcierge.APIData.Data.Address()
                    };
                    serviceAddress.BasicAddress.ZipCode   = zipcodeEntry.Text;
                    serviceAddress.BasicAddress.City      = cityEntry.Text;
                    serviceAddress.BasicAddress.StateProv = state;
                    serviceAddress.BasicAddress.Line1     = addressEntry.Text;
                    serviceAddress.BasicAddress.Line2     = apartmentEntry.Text;
                    serviceAddress.Latitude  = (decimal)gmsDetailsResult.Geometry.Location.Latitude;
                    serviceAddress.Longitude = (decimal)gmsDetailsResult.Geometry.Location.Longitude;

                    SerivesFacade serivesService = new SerivesFacade();
                    var           zipCode        = await Task.Run(() => serivesService.CheckAvailableServices(serviceAddress));

                    if (!string.IsNullOrEmpty(zipCode))
                    {
                        var latitude  = mAppServices.LastLatitude;
                        var longitude = mAppServices.LastLongitude;
                        if (!latitude.Equals(0) || !longitude.Equals(0))
                        {
                            var currentAddressDetails = await mAddressFacade.GetGmsDetails(latitude, longitude);

                            ExtendedAddress currentExtendedAddress = mAddressFacade.GetExtendedAddress(currentAddressDetails);
                            if (currentAddressDetails != null && currentExtendedAddress.BasicAddress.ZipCode == zipCode)
                            {
                                serviceAddress.Latitude  = (decimal)latitude;
                                serviceAddress.Longitude = (decimal)longitude;
                            }
                            SaveAddressPage SaveAddressPage = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                            SaveAddressPage.IsBusiness   = IsBusiness;
                            SaveAddressPage.FullName     = FullName;
                            SaveAddressPage.EmailAddress = EmailAddress;

                            await Utils.PushAsync(Navigation, SaveAddressPage, true);
                        }
                        else
                        {
                            mAppServices.CheckLocationPermission((isChecked) =>
                            {
                                Task.Run(() =>
                                {
                                    if (isChecked)
                                    {
                                        IsBusy = true;
                                        Device.BeginInvokeOnMainThread(() =>
                                        {
                                            try
                                            {
                                                mAppServices.GetLocation((isLocation) =>
                                                {
                                                    Task.Run(() =>
                                                    {
                                                        try
                                                        {
                                                            if (isLocation)
                                                            {
                                                                latitude  = mAppServices.LastLatitude;
                                                                longitude = mAppServices.LastLongitude;
                                                                if (!latitude.Equals(0) || !longitude.Equals(0))
                                                                {
                                                                    var currentAddressDetails = mAddressFacade.GetGmsDetails(latitude, longitude).Result;
                                                                    ExtendedAddress currentExtendedAddress = mAddressFacade.GetExtendedAddress(currentAddressDetails);
                                                                    if (currentAddressDetails != null && currentExtendedAddress.BasicAddress.ZipCode == zipCode)
                                                                    {
                                                                        serviceAddress.Latitude  = (decimal)latitude;
                                                                        serviceAddress.Longitude = (decimal)longitude;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                Device.BeginInvokeOnMainThread(() =>
                                                                {
                                                                    IsBusy = false;
                                                                    SaveAddressPage SaveAddressPage = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                                                                    SaveAddressPage.IsBusiness      = IsBusiness;
                                                                    SaveAddressPage.FullName        = FullName;
                                                                    SaveAddressPage.EmailAddress    = EmailAddress;
                                                                    Utils.PushAsync(Navigation, SaveAddressPage, true);
                                                                });
                                                            }
                                                        }
                                                        catch (Exception)
                                                        {
                                                            Device.BeginInvokeOnMainThread(() =>
                                                            {
                                                                IsBusy = false;
                                                                SaveAddressPage SaveAddressPage = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                                                                SaveAddressPage.IsBusiness      = IsBusiness;
                                                                SaveAddressPage.FullName        = FullName;
                                                                SaveAddressPage.EmailAddress    = EmailAddress;
                                                                Utils.PushAsync(Navigation, SaveAddressPage, true);
                                                            });
                                                        }
                                                        new System.Threading.ManualResetEvent(false).WaitOne(100);
                                                    }).ContinueWith(t =>
                                                    {
                                                        Device.BeginInvokeOnMainThread(() =>
                                                        {
                                                            IsBusy = false;
                                                            var saveAddressPage          = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                                                            saveAddressPage.FullName     = FullName;
                                                            saveAddressPage.EmailAddress = EmailAddress;
                                                            Utils.PushAsync(Navigation, saveAddressPage, true);
                                                        });
                                                    }, TaskScheduler.FromCurrentSynchronizationContext());
                                                });
                                            }
                                            catch (Exception)
                                            {
                                                IsBusy = false;
                                                SaveAddressPage SaveAddressPage = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                                                SaveAddressPage.IsBusiness      = IsBusiness;
                                                SaveAddressPage.FullName        = FullName;
                                                SaveAddressPage.EmailAddress    = EmailAddress;
                                                Utils.PushAsync(Navigation, SaveAddressPage, true);
                                            }
                                        });
                                    }
                                    else
                                    {
                                        new System.Threading.ManualResetEvent(false).WaitOne(100);
                                        Device.BeginInvokeOnMainThread(() =>
                                        {
                                            IsBusy = false;
                                            SaveAddressPage SaveAddressPage = new SaveAddressPage(ParentPage, serviceAddress, Saved);
                                            SaveAddressPage.IsBusiness      = IsBusiness;
                                            SaveAddressPage.FullName        = FullName;
                                            SaveAddressPage.EmailAddress    = EmailAddress;
                                            Utils.PushAsync(Navigation, SaveAddressPage, true);
                                        });
                                    }
                                });
                            });
                        }
                    }
                    else
                    {
                        ExtendedAddress newServiceAddress = new ExtendedAddress()
                        {
                            BasicAddress = new ColonyConcierge.APIData.Data.Address()
                        };
                        newServiceAddress.BasicAddress.ZipCode   = zipcodeEntry.Text;
                        newServiceAddress.BasicAddress.City      = cityEntry.Text;
                        newServiceAddress.BasicAddress.StateProv = state;
                        newServiceAddress.BasicAddress.Line1     = addressEntry.Text;
                        newServiceAddress.BasicAddress.Line2     = apartmentEntry.Text;
                        newServiceAddress.Latitude  = (decimal)gmsDetailsResult.Geometry.Location.Latitude;
                        newServiceAddress.Longitude = (decimal)gmsDetailsResult.Geometry.Location.Longitude;
                        var serviceNotAvailablePage = new ServiceNotAvailablePage(newServiceAddress, FullName, EmailAddress);
                        await Navigation.PushAsync(serviceNotAvailablePage);

                        //var notificator = DependencyService.Get<IToastNotificator>();
                        //await notificator.Notify(ToastNotificationType.Error, "", AppResources.AreaInvalid, TimeSpan.FromSeconds(2));
                    }
                }
                else
                {
                    var notificator = DependencyService.Get <IToastNotificator>();
                    await notificator.Notify(ToastNotificationType.Error, "", AppResources.PullDataFailMessage, TimeSpan.FromSeconds(2));
                }
            }
            catch (Exception ex)
            {
                var notificator = DependencyService.Get <IToastNotificator>();
                await notificator.Notify(ToastNotificationType.Error, "Error", ex.Message, TimeSpan.FromSeconds(2));
            }
            finally
            {
                (sender as VisualElement).IsEnabled = true;
                this.IsBusy = false;
            }
            //throw new NotImplementedException();
        }