Correct the Method and rename Method

This commit is contained in:
franc
2025-04-16 15:18:39 +02:00
parent eb6d82a979
commit b8814ce708
2 changed files with 13 additions and 16 deletions
@@ -17,6 +17,6 @@
Task<Recipe> CreateRecipeForCategoryAsync(Category category, string name, string description, Difficulty difficulty, int servings, TimeSpan preparationTime, TimeSpan cookingTime);
Task<IEnumerable<Recipe>> GetRecipesBySearchQueryAsync(string query);
Task<IEnumerable<Recipe>> SerachRecipeAndIngredientAsync(string query);
}
}
@@ -147,24 +147,21 @@
await _context.SaveChangesAsync();
}
public async Task<IEnumerable<Recipe>> GetRecipesBySearchQueryAsync(string query)
public async Task<IEnumerable<Recipe>> SerachRecipeAndIngredientAsync(string searchTerm)
{
if (string.IsNullOrWhiteSpace(query))
{
return await _context.Recipes
.Include(r => r.RecipeIngredients)
.ThenInclude(ri => ri.Ingredient)
.ToListAsync();
}
query = query.ToLower();
return await _context.Recipes
var queryable = _context.Recipes
.Include(r => r.RecipeIngredients)
.ThenInclude(ri => ri.Ingredient)
.Where(r => r.Name.ToLower().Contains(query) ||
r.RecipeIngredients.Any(ri => ri.Ingredient.Name.ToLower().Contains(query)))
.ToListAsync();
.AsQueryable();
if (!string.IsNullOrWhiteSpace(searchTerm))
{
searchTerm = searchTerm.ToLower();
queryable = queryable.Where(r => r.Name.ToLower().Contains(searchTerm) ||
r.RecipeIngredients.Any(ri => ri.Ingredient.Name.ToLower().Contains(searchTerm)));
}
return await queryable.ToListAsync();
}
public async Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty)