コード例 #1
0
        async Task ExecuteSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;

            try
            {
                if (Item.Id == null)
                {
                    await table.CreateItemAsync(Item);
                }
                else
                {
                    await table.UpdateItemAsync(Item);
                }
                MessagingCenter.Send <MealDetailViewModel>(this, "ItemsChanged");
                await Application.Current.MainPage.Navigation.PopAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"[MealDetail] Save error: {ex.Message}");
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
        private async Task UpdateUserLocation(User user)
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 25;

            try
            {
                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(15));

                if (position != null)
                {
                    //userTable = await CloudService.GetTableAsync<User>();
                    CultureInfo culture = CultureInfo.CurrentCulture;
                    user.Longitude = position.Longitude; user.Latitude = position.Latitude; user.CultureInfo = culture.ToString();
                    await userTable.UpdateItemAsync(user);

                    await CloudService.SyncOfflineCacheAsync();
                }
            }
            catch (TaskCanceledException e)
            {
                Debug.WriteLine("Error " + e.Message);
                Debug.WriteLine("Unable to get location, may need to increase timeout: " + e);
                var answer = await Application.Current.MainPage.DisplayAlert("Detecting location error", "Please turn on GPS. Would you like to try again?", "Yes", "No");

                // do nothing
                Debug.WriteLine("Answer: " + answer);
                if (answer.Equals("Yes"))
                {
                    Navigation.InsertPageBefore(new JoinEventLoadingPage(), this);
                    await Navigation.PopAsync();
                }
                else
                {
                    Navigation.InsertPageBefore(new HomePage(), this);
                    await Navigation.PopAsync();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error " + e.Message);
                Debug.WriteLine("Unable to get address at this moment!");
                var answer = await Application.Current.MainPage.DisplayAlert("Detecting location error", "Please turn on GPS. Would you like to try again?", "Yes", "No");

                // do nothing
                Debug.WriteLine("Answer: " + answer);
                if (answer.Equals("Yes"))
                {
                    Navigation.InsertPageBefore(new JoinEventLoadingPage(), this);
                    await Navigation.PopAsync();
                }
                else
                {
                    Navigation.InsertPageBefore(new HomePage(), this);
                    await Navigation.PopAsync();
                }
            }
        }