private static IEnumerable <RecipeSearchModel> FilterProducts(this IRecipeManager recipeManager, IEnumerable <RecipeSearchModel> data, ViewModels.Filter filter) { if (filter.CategoryId.HasValue) { return(data.Where(p => (!filter.GlutenFree || p.GlutenFree) && recipeManager.InCategory(p.Id, filter.CategoryId.Value) && p.InRangeCarbohydrate(filter.CarbRange) && p.InRangeFat(filter.FatRange) && p.InRangeProtein(filter.ProteinRange))); } else { return(data.Where(p => (!filter.GlutenFree || p.GlutenFree) && p.InRangeCarbohydrate(filter.CarbRange) && p.InRangeFat(filter.FatRange) && p.InRangeProtein(filter.ProteinRange))); } }