Correct the Method and rename Method
This commit is contained in:
@@ -17,6 +17,6 @@
|
|||||||
|
|
||||||
Task<Recipe> CreateRecipeForCategoryAsync(Category category, string name, string description, Difficulty difficulty, int servings, TimeSpan preparationTime, TimeSpan cookingTime);
|
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();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Recipe>> GetRecipesBySearchQueryAsync(string query)
|
public async Task<IEnumerable<Recipe>> SerachRecipeAndIngredientAsync(string searchTerm)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(query))
|
var queryable = _context.Recipes
|
||||||
{
|
|
||||||
return await _context.Recipes
|
|
||||||
.Include(r => r.RecipeIngredients)
|
.Include(r => r.RecipeIngredients)
|
||||||
.ThenInclude(ri => ri.Ingredient)
|
.ThenInclude(ri => ri.Ingredient)
|
||||||
.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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
query = query.ToLower();
|
return await queryable.ToListAsync();
|
||||||
|
|
||||||
return await _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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty)
|
public async Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty)
|
||||||
|
|||||||
Reference in New Issue
Block a user