public PagedResult <RecipePreview> Get(RecipeGetFilter getFilter) { if (getFilter.PageNumber < 1) { getFilter.PageNumber = 1; } if (getFilter.PageSize < 6) { getFilter.PageSize = 6; } Func <Recipe, bool> ingredientFilterFunc = recipe => true; Func <Recipe, bool> categoryFilterFunc = recipe => true; Func <Recipe, bool> preparationTimeFilterFunc = recipe => true; Func <Recipe, bool> cookingTimeFilterFunc = recipe => true; if (getFilter.IngredientNames != null) { ingredientFilterFunc = recipe => { foreach (var filterIngredient in getFilter.IngredientNames) { bool found = false; foreach (var recipeIngredient in recipe.Ingredients) { if (recipeIngredient.Name.Contains(filterIngredient, StringComparison.OrdinalIgnoreCase)) { found = true; break; } } if (!found) { return(false); } } return(true); }; } if ((Category)getFilter.CategoryFilter != Category.Default) { categoryFilterFunc = recipe => recipe.Category.HasFlag((Category)getFilter.CategoryFilter); } if (getFilter.CookingTimeFilter != default) { cookingTimeFilterFunc = recipe => recipe.CookingTime.TotalSeconds <= getFilter.CookingTimeFilter; } if (getFilter.PreparationTimeFilter != default) { preparationTimeFilterFunc = recipe => recipe.PreparationTime.TotalSeconds <= getFilter.PreparationTimeFilter; } Func <Recipe, bool> filter = recipe => { return (ingredientFilterFunc.Invoke(recipe) && categoryFilterFunc.Invoke(recipe) && preparationTimeFilterFunc.Invoke(recipe) && cookingTimeFilterFunc.Invoke(recipe)); }; return(recipeService.Get(getFilter.PageNumber, getFilter.PageSize, filter)); }
public IActionResult Get([FromBody] RecipeGetFilter filter) { var result = recipeLogic.Get(filter); return(Ok(result)); }