public void GenerateMeals() { //gets the list of available recipes recipes = RecipeTableDB.GetRecipeList(); for (int i = 0; i < 3; i++) { newMeal = new Meal(); index = rand.Next(recipes.Count); if (index < recipes.Count) { newMeal.Name = recipes.ElementAt(index).Name; recipeIngredientLink = RecipeIngredLinkTableDB.GetIngredientsForRecipe(recipes.ElementAt(index).Id); StringBuilder sb = new StringBuilder(); foreach (RecipeIngredLinkModel link in recipeIngredientLink) { //ingredients.Add(IngredientTableDB.GetIngredient(link.IngredientId)); sb.Append(IngredientTableDB.GetIngredient(link.IngredientId).Name + "\n"); } newMeal.Ingredients = sb.ToString(); newMeal.Instructions = recipes.ElementAt(index).Instructions; ob_mealPlan.Add(newMeal); //remove the selected recipe from the list to avoid repeats recipes.RemoveAt(index); } } }
public static void ui_deleteIngredientsFromCurrentRecipe(int id, int selectedRecipe, int selectedIngredient, ref ObservableCollection <IngredientModel> ingredientList) { //int id = Convert.ToInt32(listboxIngredients.SelectedValue); //get the ingredient IngredientModel ingredientToDelete = IngredientTableDB.GetIngredient(id); //delete the meal link List <RecipeIngredLinkModel> ingred = RecipeIngredLinkTableDB.GetIngredientsForRecipe(selectedRecipe); RecipeIngredLinkModel linkToDelete = ingred.Find(x => x.IngredientId.Equals(id)); RecipeIngredLinkTableDB.RemoveIngredientFromRecipe(linkToDelete); //delete the ingredient IngredientTableDB.RemoveIngredient(ingredientToDelete); //remove the deleted ingredient from the listbox ingredientList.RemoveAt(selectedIngredient); }
//fully deletes the selected recipe from both the meal collection as well as the database //also deletes all ingredients that the recipe had as well as the links public static void ui_deleteRecipeFromEverything(RecipeModel recipeToDelete, ref ObservableCollection <RecipeModel> mealList) { List <RecipeIngredLinkModel> ingredientsAndLinksToDelete = RecipeIngredLinkTableDB.GetIngredientsForRecipe(recipeToDelete.Id); Database.RecipeTableDB.RemoveRecipe(recipeToDelete); mealList.Remove(recipeToDelete); //delete the ingredients foreach (RecipeIngredLinkModel ingred in ingredientsAndLinksToDelete) { IngredientTableDB.RemoveIngredient(IngredientTableDB.GetIngredient(ingred.IngredientId)); } //delete the link recipeingredlink table foreach (RecipeIngredLinkModel link in ingredientsAndLinksToDelete) { RecipeIngredLinkTableDB.RemoveIngredientFromRecipe(link); } }
private void btnAccept_Click(object sender, RoutedEventArgs e) { IngredientModel ingredient = new IngredientModel(); ingredient.Name = tbName.Text.ToString(); int id = IngredientTableDB.AddIngredient(ingredient); ingredient.Id = id; ob_ingredientName.Add(ingredient); //create the link between ingredient and recipe RecipeIngredLinkModel link = new RecipeIngredLinkModel(); link.IngredientId = id; link.RecipeId = recipeId; RecipeIngredLinkTableDB.AddIngredientToRecipe(link); this.Close(); }
private void findPotentialRecipeInDatabase(bool exclusive) { try { potentialRecipe = RecipeTableDB.SearchAvailableRecipe(new List <IngredientModel>(ob_ingredients), exclusive); foreach (RecipeModel recipe in potentialRecipe) { newMeal = new Meal(); newMeal.Name = recipe.Name; newMeal.Instructions = recipe.Instructions; tempLink = RecipeIngredLinkTableDB.GetIngredientsForRecipe(recipe.Id); StringBuilder sb = new StringBuilder(); foreach (RecipeIngredLinkModel link in tempLink) { //ingredients.Add(IngredientTableDB.GetIngredient(link.IngredientId)); sb.Append(IngredientTableDB.GetIngredient(link.IngredientId).Name + "\n"); } newMeal.Ingredients = sb.ToString(); Console.WriteLine(newMeal.Name); if (newMeal != null) { ob_meal.Add(newMeal); } } } catch (Exception ex) { return; } }