async void Delete(object sender, EventArgs e) { IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); var spec = (sender as MenuItem).BindingContext as FoodSpecial; await _foodSpecService.Delete(spec.SpecialId); _foodSpecials.Remove(spec); }
async Task PopulateSpecsList() { IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); _allSpecs = await _foodSpecService.GetFoodSpecsByCoordinates(); switch (_specSort) { case SpecSort.Upcoming: await SetUpcoming(); break; case SpecSort.ByDay: await SetByDay(_daySort); break; } }
public LoadingPage() { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); BackgroundColor = Color.White; Device.BeginInvokeOnMainThread(async() => { //try //{ IsBusy = true; var coordinates = await Utils.GetLatAndLong(); LoadingMessage.Text = "Loading Restaurants..."; IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); var foodSpecs = await _foodSpecService.GetFoodSpecsByCoordinates(); IsBusy = false; LoadingContent.IsVisible = false; await Navigation.PushModalAsync(new FoodSpecsPage(), false); //}catch(Exception ex){ // await DisplayAlert("Error", ex.Message, "cancel"); // //await DisplayAlert("Error", "There was an error with the web service, please try again later", "Cancel"); //} }); }
async void ManageSpec(object sender, EventArgs e) { var action = await DisplayActionSheet("Actions", "Cancel", "Delete", new string[] { "Edit", "Copy", "Report" }); switch (action) { #region Case Delete case "Delete": var confirm = await DisplayAlert("Delete", "Are you sure you want to delete " + _spec.Title + "?", "Yes", "No"); if (confirm) { UserDialogs.Instance.ShowLoading("Deleting", MaskType.Black); IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); await _foodSpecService.Delete(_spec.SpecialId); UserDialogs.Instance.HideLoading(); await Navigation.PopAsync(); } break; #endregion #region Case Edit case "Edit": var editFoodSpecPage = new AddEditFoodSpec(_restaurant, FoodSpecialActions.Edit, _spec); editFoodSpecPage.Disappearing += (send, args) => { SetFields(); }; await Navigation.PushModalAsync(editFoodSpecPage); break; #endregion } }
/// <summary> /// Saves thes food spec to the database. /// </summary> async Task AddUpdate() { //Prevent double tap.. we'll see how this works if (tapped) { return; } tapped = true; //If validation fails, return if (ValidateForm() == false) { await DisplayAlert("Validation", errorMessage.ToString(), "OK"); tapped = false; return; } UserDialogs.Instance.ShowLoading("Saving", MaskType.Black); IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); #region Create new spec var newFoodSpec = new FoodSpecial { SpecialId = _spec != null ? _spec.SpecialId : 0, //new spec id is 0 Title = txtTitle.Text, Description = txtDescription.Text, Sunday = swSunday.IsToggled, Monday = swMonday.IsToggled, Tuesday = swTuesday.IsToggled, Wednesday = swWednesday.IsToggled, Thursday = swThursday.IsToggled, Friday = swFriday.IsToggled, Saturday = swSaturday.IsToggled, RestaurantId = _restaurantId }; #endregion //All day and set times are mutually exclusive if (swAllDay.IsToggled) { newFoodSpec.AllDay = true; } else { newFoodSpec.StartTime = tpStartTime.Time; newFoodSpec.EndTime = tpEndTime.Time; } try { await _foodSpecService.AddUpdate(newFoodSpec); UserDialogs.Instance.HideLoading(); await Navigation.PopModalAsync(true); tapped = false; } catch (Exception ex) { UserDialogs.Instance.HideLoading(); await DisplayAlert("Error", "Due to an error your food special has not been saved", "OK"); tapped = false; } }