private async Task ExecuteRemoveFavouriteRecipe(Recipe recipe) { try { var toRemove = Recipes.First(x => x.Id.Equals(recipe.Id)); Recipes.Remove(toRemove); await ExecuteSaveFavouriteRecipes(); } catch (InvalidOperationException e) { Debug.WriteLine("There was no favourite item with id = " + recipe.Id); } }
public async Task ExecuteGetRecipeAsync(string id) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("X-Mashape-Key", "B96xQQNUeFmshzTERF80qvDxvveAp1SZYaJjsnJmsAuxCzt3Wi"); using (HttpResponseMessage response = await client.GetAsync(GET_SINGLE_URL + id.ToString())) { if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); Debug.WriteLine(content); RecipeModel model= await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<RecipeModel>(content)); RecipeItem = model.Recipe; } } } }
private async Task ExecuteAddFavouriteRecipe(Recipe recipe) { Recipes.Add(recipe); await ExecuteSaveFavouriteRecipes(); }
public static async void RemoveFromFavouritesAsync(Recipe recipe) { await _sampleDataSource.ExecuteRemoveFavouriteRecipe(recipe); }
public static async void AddToFavouritesAsync(Recipe recipe) { await _sampleDataSource.ExecuteAddFavouriteRecipe(recipe); }