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); } } }