From bdf5f4f727ed1c707f5d728bd7f56de05535855c Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 12 May 2023 07:46:06 +0300 Subject: [PATCH] Order found products by IsOnWarehouse property --- .../Controllers/SearchController.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/RhSolutions.Api/Controllers/SearchController.cs b/RhSolutions.Api/Controllers/SearchController.cs index 92d93d0..cf35209 100644 --- a/RhSolutions.Api/Controllers/SearchController.cs +++ b/RhSolutions.Api/Controllers/SearchController.cs @@ -4,24 +4,25 @@ using RhSolutions.Models; namespace RhSolutions.Api.Controllers { - [Route("api/[controller]")] - public class SearchController : ControllerBase - { - private RhSolutionsContext context; + [Route("api/[controller]")] + public class SearchController : ControllerBase + { + private RhSolutionsContext context; - public SearchController(RhSolutionsContext context) - { - this.context = context; - } + public SearchController(RhSolutionsContext context) + { + this.context = context; + } - [HttpGet] - public IAsyncEnumerable SearchProducts([FromQuery] string query) - { - return context.Products - .Where(p => EF.Functions.ToTsVector( - "russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines)})) - .Matches(EF.Functions.WebSearchToTsQuery("russian", query))) - .AsAsyncEnumerable(); - } - } + [HttpGet] + public IAsyncEnumerable SearchProducts([FromQuery] string query) + { + return context.Products + .Where(p => EF.Functions.ToTsVector( + "russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines)})) + .Matches(EF.Functions.WebSearchToTsQuery("russian", query))) + .OrderByDescending(p => p.IsOnWarehouse) + .AsAsyncEnumerable(); + } + } } \ No newline at end of file