update search and products

This commit is contained in:
MarcEricMartel
2022-10-16 17:33:58 -07:00
parent dbc1c78f07
commit 272c232530
7 changed files with 51 additions and 18 deletions

View File

@@ -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);
}