Beispiel #1
0
        public async void OnBookmarkClicked(object sender, EventArgs e)
        {
            if (this.BindingContext != null)
            {
                var button = (Button)sender;
                button.IsEnabled = false;
                busy.IsVisible   = true;
                busy.IsRunning   = true;
                if (!_bookmarked)
                {
                    var recipe      = this.BindingContext as Recipe;
                    var newBookmark = new BookmarkRequest {
                        userId = App.AuthManager.loggedInUser.UserId, RecipeId = recipe.id, Title = recipe.title, ImageURL = recipe.image
                    };
                    var response = await App.APImanager.AddBookmark(newBookmark);

                    if (response.success)
                    {
                        _bookmarked = true;
                        _bookmarkId = response.bookmarks[0].BookmarkId;
                        UpdateBookMarkButton();
                    }
                    else
                    {
                        // handle failure
                        await DisplayAlert("Error", response.message, "Okay");
                    }
                }
                else
                {
                    var response = await App.APImanager.DeleteBookmark(_bookmarkId);

                    if (response.success)
                    {
                        _bookmarked = false;
                        _bookmarkId = Guid.Empty;
                        UpdateBookMarkButton();
                    }
                    else
                    {
                        // handle failure
                        await DisplayAlert("Error", response.message, "Okay");
                    }
                }
                busy.IsVisible   = false;
                busy.IsRunning   = false;
                button.IsEnabled = true;
            }
        }
Beispiel #2
0
        // POST a new bookmark
        public async Task <BookmarkResponse> AddBookmark(BookmarkRequest bookmark)
        {
            var uri = new Uri(string.Format(Keys.WebAPI + "/bookmark", string.Empty));

            try
            {
                var json    = JsonConvert.SerializeObject(bookmark);
                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 <BookmarkResponse>(JSONstring));
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
 public Task <BookmarkResponse> AddBookmark(BookmarkRequest bookmark)
 {
     return(_APIservice.AddBookmark(bookmark));
 }