Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        //Functions


        //Takes the current recipe selected in the cmbMeal combobox and populates listIngredients with that recipe's current ingredients
        public static ObservableCollection <IngredientModel> ui_addIngredientToListBoxCollection(int recipeId)
        {
            // int recipeId = (int)cmbMeal.SelectedValue;
            ObservableCollection <IngredientModel> ob_ingredients = new ObservableCollection <IngredientModel>();

            list_ingredients = Database.RecipeIngredLinkTableDB.GetIngredientsForRecipe(recipeId);

            //takes all of the ingredients in the ingredientname list and puts them into an observable collection -- Makes it easier to data bind
            foreach (RecipeIngredLinkModel ingredient in list_ingredients)
            {
                int             id = ingredient.IngredientId;
                IngredientModel crntRecipeIngred = IngredientTableDB.GetIngredient(id);
                ob_ingredients.Add(crntRecipeIngred);
            }
            return(ob_ingredients);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        //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);
            }
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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;
            }
        }