private void StoreFoodIngredientsWithoutAllergens(List <Food> food) { var ingredientsThatDontContainGivenAllergen = food .SelectMany(p => p.Ingredients) .GroupBy(p => p) .Select(p => p.Key) .Where(p => !IngredientsWithAllergens.Contains(p)) .ToList(); IngredientsWithoutAllergens.AddRange(ingredientsThatDontContainGivenAllergen); }
private void CountSafeIngredientsInFoods() => ApparitionsOfIngredientsWithoutAllergensInFood = _foods .SelectMany(food => food.Ingredients .Where(ingredient => IngredientsWithoutAllergens.Contains(ingredient)) .Select(_ => food)) .Count();
private void RefreshIngredientsWithoutAllergens() { IngredientsWithoutAllergens = IngredientsWithoutAllergens.Distinct().ToList(); IngredientsWithoutAllergens.RemoveAll(i => IngredientsWithAllergens.Contains(i)); }