예제 #1
0
        public Recipe FilterRecipesGroup(Recipe recipes)
        {
            var restrictions = GetAllRestrictions();

            int count         = recipes.meals.Length;
            var filteredMeals = new Meal[count];
            int index         = 0;

            if (restrictions != null)
            {
                foreach (var item in recipes.meals)
                {
                    bool isBad       = false;
                    var  ingredients = RecipeMethods.AddIngredients(item);

                    foreach (var name in restrictions)
                    {
                        var ingred = name.Id.ToLower();

                        if (ingredients.Contains(ingred))
                        {
                            isBad = true;
                        }
                    }
                    if (isBad == false)
                    {
                        filteredMeals[index] = item;
                    }
                    index++;
                }
            }
            Recipe filteredRecipes = new Recipe();

            filteredRecipes.meals = filteredMeals;
            return(filteredRecipes);
        }
예제 #2
0
        public Recipe FilterRecipes(Recipe recipes)
        {
            var restrictions = GetAllRestrictions();

            int count         = recipes.meals.Length;
            var filteredMeals = new Meal[count];
            int index         = 0;

            if (restrictions != null)
            {
                foreach (var item in recipes.meals)
                {
                    bool isBad        = false;
                    var  ingredients  = RecipeMethods.AddIngredients(item);
                    var  instructions = item.strInstructions.ToLower();

                    foreach (var name in restrictions)
                    {
                        var ingred = name.Id.ToLower();

                        if (ingredients.Contains(ingred))
                        {
                            isBad = true;
                        }
                    }
                    foreach (var name in restrictions)
                    {
                        var ingred = name.Id.ToLower();

                        if (instructions.Contains(ingred))
                        {
                            isBad = true;
                        }
                    }
                    if (isBad == false)
                    {
                        filteredMeals[index] = item;
                    }
                    index++;
                }
            }
            Recipe filteredRecipes = new Recipe();

            filteredRecipes.meals = filteredMeals;

            Recipe myRecipes = new Recipe();

            count = 0;
            foreach (var recipe in filteredRecipes.meals)
            {
                if (recipe != null)
                {
                    count++;
                }
            }
            if (count != 0)
            {
                Meal[] newMeals = new Meal[count];
                count = 0;
                foreach (var recipe in filteredRecipes.meals)
                {
                    if (recipe != null)
                    {
                        newMeals[count] = recipe;
                        count++;
                    }
                }
                filteredRecipes.meals = newMeals;
            }
            else
            {
                Meal[] mealStuff = new Meal[1];
                filteredRecipes.meals = mealStuff;
            }
            return(filteredRecipes);
        }