public static async void UpdateNutrition(SingleRecipeData selectedRecipe) { try { var SingleRecipeObject = (await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == selectedRecipe.RecipeTitle) .Where(a => a.Object.IngredientsList.Count == selectedRecipe.Items.Count).FirstOrDefault();; await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(SingleRecipeObject.Key) .Child("NutritionValues") .PutAsync(new NutritionFacts(selectedRecipe.NutritionValues)); return; } catch (Exception e) { Debug.WriteLine($"Error:{e}"); } }
public static async Task <bool> UpdateRecipeTitle(string name, SingleRecipeData data) { try { var toUpdateTitle = (await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == data.RecipeTitle).FirstOrDefault(); await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(toUpdateTitle.Key) .PutAsync(new RecipeItems() { RecipeName = name, IngredientsList = data.Items.ToList(), NutritionValues = data.NutritionValues, RecipeRating = data.RatingStars, Instructions = data.Instructions });; return(true); } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return(false); } }
// Delete Recipe from Database public static async Task <bool> DeleteRecipe(SingleRecipeData toDelete) { try { var SingleRecipeObject = (await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == toDelete.RecipeTitle) .Where(a => a.Object.IngredientsList.Count == toDelete.Items.Count).FirstOrDefault();; await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(SingleRecipeObject.Key) .DeleteAsync(); return(true); } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return(false); } }
public static async void UpdateRecipeEdit(SingleRecipeData selectedRecipe, IngredientItem unEditedIngredient, IngredientItem editedIngredient) { try { var SingleRecipeObject = (await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == selectedRecipe.RecipeTitle) .Where(a => a.Object.IngredientsList.Count == selectedRecipe.Items.Count).FirstOrDefault();; int editIndex = -1; for (int i = 0; i < selectedRecipe.Items.Count; i++) { if (selectedRecipe.Items.ElementAt(i) == unEditedIngredient) { editIndex = i; } } // if index was not found(it should) if (editIndex == -1) { Debug.WriteLine("UpdateRecipeEdit failed to match index of item to be edited"); return; } await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(SingleRecipeObject.Key) .Child("IngredientsList") .Child(editIndex.ToString()) .PutAsync(new IngredientItem(editedIngredient)); await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(SingleRecipeObject.Key) .Child("NutritionValues") .PutAsync(new NutritionFacts(selectedRecipe.NutritionValues)); } catch (Exception e) { Debug.WriteLine($"Error:{e}"); } }
public static async void SaveInstructions(SingleRecipeData recipe, List <InstructionItem> instructions) { try { var SingleRecipeObject = (await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == recipe.RecipeTitle) .FirstOrDefault();; await firebase .Child(Application.Current.Properties["Id"].ToString()) .Child("Recipes") .Child(SingleRecipeObject.Key) .Child("Instructions") .PutAsync(new List <InstructionItem>(instructions)); } catch (Exception e) { Debug.WriteLine($"Error:{e}"); } }