Example #1
0
        private async void SaveCommand()
        {
            if (String.IsNullOrEmpty(Name))
            {
                await Application.Current.MainPage.DisplayAlert("Alert ", "Please add a name ", "OK");
            }
            else
            {
                if (UseLocation)
                {
                    try
                    {
                        var location = await Geolocation.GetLastKnownLocationAsync();

                        if (location != null)
                        {
                            var placemarks = await Geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude);

                            var placemark = placemarks?.FirstOrDefault();
                            notavailable = "It seems that part(s) of your selected address is not available.Lucky for us we have google .";
                            if (placemarks != null)
                            {
                                Location = $"{placemark.FeatureName ?? notavailable}-{placemark.Locality ?? notavailable },{placemark.SubAdminArea ?? notavailable}.";
                            }
                        }

                        Location = "Location not available at this time";
                    }
                    catch (FeatureNotSupportedException fnsEx)
                    {
                        return;
                    }
                }
                NewItem e = new NewItem()
                {
                    ItemName     = this.Name,
                    ItemNotes    = this.Notes,
                    IsDone       = this.Done,
                    Date         = this.BookingDate.Date,
                    UserLocation = this.Location,
                };

                TodoInfo ex   = new TodoInfo();
                var      list = ex.SaveItems(e);


                await Application.Current.MainPage.DisplayAlert("Amazing! ", "List saved!! ", "OK");

                //await Application.Current.MainPage.Navigation.PushAsync(new MainNavigationPage());
                await App.Current.MainPage.Navigation.PopAsync();

                App.NotificationVm.BindData(true);
            }
        }