Пример #1
0
        public async void OnAddToPlanClicked(object sender, EventArgs e)
        {
            var mealStrings = new[] { "Breakfast", "Lunch", "Dinner", "Snack", "Dessert" };
            var button      = (Button)sender;

            button.IsEnabled = false;
            var action = await DisplayActionSheet("Which Meal?", "Cancel", null, mealStrings);

            if (mealStrings.Contains(action))
            {
                // Post this Meal Plan to WebAPI
                var newPlan = new PlanRequest {
                    userId = App.AuthManager.loggedInUser.UserId, date = selectedDate, meal = action, recipe = selectedRecipe
                };
                JsonResponse response = await App.APImanager.AddPlan(newPlan);

                // On Success, pop this page from Navigation
                if (response.success)
                {
                    await Navigation.PopAsync();
                }
                else
                {
                    // handle failure
                    await DisplayAlert("Error", response.message, "Okay");
                }
            }
            button.IsEnabled = true;
        }
Пример #2
0
        public async void OnAddToPlanClicked(object sender, EventArgs e)
        {
            if (this.BindingContext != null)
            {
                var button = (Button)sender;
                button.IsEnabled = false;
                busy.IsVisible   = true;
                busy.IsRunning   = true;
                var recipe = this.BindingContext as Recipe;
                // If this page was instantiated from meal planning home, it would already have a date attached
                // If no date is attached, show the calendar view
                if (_activeDate == null)
                {
                    var page = new AddToPlanFromRecipePage(recipe);
                    await Navigation.PushAsync(page);

                    // If a date is attached, just jump straight to posting the new plan
                }
                else
                {
                    var mealStrings = new[] { "Breakfast", "Lunch", "Dinner", "Snack", "Dessert" };
                    var action      = await DisplayActionSheet("Which Meal?", "Cancel", null, mealStrings);

                    if (mealStrings.Contains(action))
                    {
                        // Post this Meal Plan to WebAPI
                        var newPlan = new PlanRequest {
                            userId = App.AuthManager.loggedInUser.UserId, date = _activeDate, meal = action, recipe = recipe
                        };
                        JsonResponse response = await App.APImanager.AddPlan(newPlan);

                        // On Success, pop this page from Navigation
                        if (response.success)
                        {
                            var navStack = this.Navigation.NavigationStack;
                            // Remove the search page before popping, jumps back to Meal Plan home page
                            Navigation.RemovePage(navStack[navStack.Count - 2]);
                            await Navigation.PopAsync();
                        }
                        else
                        {
                            // handle failure
                            await DisplayAlert("Error", response.message, "Okay");
                        }
                    }
                }
                busy.IsVisible   = false;
                busy.IsRunning   = false;
                button.IsEnabled = true;
            }
        }
Пример #3
0
        // POST a new plan
        public async Task <JsonResponse> AddPlan(PlanRequest plan)
        {
            var uri = new Uri(string.Format(Keys.WebAPI + "/plan", string.Empty));

            try
            {
                var json    = JsonConvert.SerializeObject(plan);
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(uri, content);

                var JSONstring = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <JsonResponse>(JSONstring));
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
Пример #4
0
 public Task <JsonResponse> AddPlan(PlanRequest plan)
 {
     return(_APIservice.AddPlan(plan));
 }