public async Task<bool> AddToFavorite(Recipe r) { try { string json = JsonConvert.SerializeObject(r); HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("api/recipes", content); if ((response.IsSuccessStatusCode) || (response.StatusCode.ToString().Equals("Conflict"))) { String recipeId = r.recipe_id + currentApp.GlobalInstance.userId; UserFavorite uFav = new UserFavorite(recipeId, currentApp.GlobalInstance.userId, r.recipe_id); string jsonfav = JsonConvert.SerializeObject(uFav); HttpContent contentfav = new StringContent(jsonfav, Encoding.UTF8, "application/json"); HttpResponseMessage responsefav = await client.PostAsync("api/userfavorites", contentfav); if (responsefav.IsSuccessStatusCode) { return true; } return false; } } catch (HttpRequestException e) { return false; } return false; }
public async Task<bool> RemoveFavorite(Recipe r) { try { HttpResponseMessage response = await client.DeleteAsync("api/userfavorites/" + r.recipe_id + currentApp.GlobalInstance.userId); if (response.IsSuccessStatusCode) { return true; } } catch (HttpRequestException e) { return false; } return false; }