Exemple #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);
                }
            }
        }
Exemple #2
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;
            }
        }
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     ob_recipeName.ElementAt(index).Instructions = tbInstructions.Text.ToString();
     RecipeTableDB.UpdateRecipeInstructions(ob_recipeName.ElementAt(index));
     this.Close();
 }