update search and products
This commit is contained in:
@@ -18,15 +18,19 @@ public class SearchController : Controller {
|
||||
}
|
||||
|
||||
[HttpPost(Name = "Search")]
|
||||
public IEnumerable<Product> Post(string query) {
|
||||
public IEnumerable<Product> Post(string query, bool? preview) {
|
||||
HashSet<Product> products = new();
|
||||
|
||||
query = query.Trim();
|
||||
|
||||
try { // Pour faire une liste priorisée.
|
||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
||||
if (preview.HasValue && preview == true)
|
||||
products = _context.Products.Where(x => x.Title.Contains(query)).Take(3).ToHashSet();
|
||||
else {
|
||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user