public IQueryable <Product> SearchProduct(ProductSearchOptions options) { if (options == null) { return(null); } var query = dbContext .Set <Product>() .AsQueryable(); if (options.ProductId != null) { query = query.Where(p => p.ProductId == options.ProductId); } if (options.PriceFrom != null) { query = query.Where(p => p.Price >= options.PriceFrom); } if (options.PriceTo != null) { query = query.Where(p => p.Price <= options.PriceTo); } if (options.Categories != null) { } query = query.Take(500); return(query); }
public Connect.SearchOptions Build(Connect.SearchSettings searchSettings, ProductSearchOptions searchOptions) { Assert.ArgumentNotNull(searchSettings, nameof(searchSettings)); Assert.ArgumentNotNull(searchOptions, nameof(searchOptions)); if (!string.IsNullOrWhiteSpace(searchOptions.SortField) && !searchSettings.SortFieldNames.Contains( searchOptions.SortField, StringComparer.InvariantCultureIgnoreCase)) { throw new Exception("Sort field not found"); } return(new Connect.SearchOptions { SearchKeyword = searchOptions.SearchKeyword, Facets = this.GetFacetsIntersection(searchSettings.Facets, searchOptions.Facets), StartPageIndex = searchOptions.PageNumber, NumberOfItemsToReturn = searchOptions.PageSize > 0 ? searchOptions.PageSize : searchSettings.ItemsPerPage, CategoryId = searchOptions.CategoryId, SortField = !string.IsNullOrEmpty(searchOptions.SortField) ? searchOptions.SortField : searchSettings.SortFieldNames?.FirstOrDefault(), SortDirection = searchOptions.SortDirection == SortDirection.Asc ? Connect.SortDirection.Asc : Connect.SortDirection.Desc }); }
// GET: Products public ActionResult Index(ProductSearchOptions searchOptions) { var searchedProducts = searchOptions .ApplyOn(db.Products) .Include(p => p.Seller) .ToList() .Select(p => new IndexProduct(p)); ViewData["SearchOptions"] = searchOptions; return(View(searchedProducts)); }
public Result <ProductSearchResults> GetProducts(ProductSearchOptions productSearchOptions) { Assert.ArgumentNotNull(productSearchOptions, nameof(productSearchOptions)); var searchSettings = this.searchSettingsProvider.GetSearchSettings(productSearchOptions.CategoryId); var searchOptions = this.searchOptionsBuilder.Build(searchSettings, productSearchOptions); var searchResults = this.searchService.GetProducts(searchOptions); return(new Result <ProductSearchResults>( this.searchMapper.Map <Connect.SearchResults <Product>, ProductSearchResults>(searchResults))); }
public Connect.SearchOptions Build(Connect.SearchSettings searchSettings, ProductSearchOptions searchOptions) { Assert.ArgumentNotNull(searchSettings, nameof(searchSettings)); Assert.ArgumentNotNull(searchOptions, nameof(searchOptions)); return(new Connect.SearchOptions { SearchKeyword = searchOptions.SearchKeyword, Facets = this.GetFacetsIntersection(searchSettings.Facets, searchOptions.Facets), StartPageIndex = searchOptions.PageNumber, NumberOfItemsToReturn = searchOptions.PageSize > 0 ? searchOptions.PageSize : searchSettings.ItemsPerPage, CategoryId = searchOptions.CategoryId, SortField = !string.IsNullOrEmpty(searchOptions.SortField) ? searchOptions.SortField : searchSettings.SortFieldNames?.FirstOrDefault(), SortDirection = searchOptions.SortDirection == SortDirection.Asc ? Connect.SortDirection.Asc : Connect.SortDirection.Desc }); }
public ActionResult Search(ProductSearchOptions selectedItems) { try { if (selectedItems.Name == null) { selectedItems.Name = ""; } if (selectedItems.Properties == null) { selectedItems.Properties = new List <Models.Property>(); } var category = ApplicationContext.Services.ContentService.GetById(selectedItems.CategoryId); var products = category.Children(); List <int> ids = new List <int>(); foreach (var product in products) { bool ok = true; if (!string.IsNullOrEmpty(selectedItems.Name.Trim()) && !product.Name.Trim().ToLower().Contains(selectedItems.Name.Trim().ToLower())) { continue; } dynamic res = JsonConvert.DeserializeObject((string)product.Properties["propertiesValues"].Value); for (int i = 0; i < selectedItems.Properties.Count; ++i) { dynamic currRow = res.cells.First; while (currRow != null) { if (currRow.First.value == selectedItems.Properties[i].Name) { foreach (var propValue in selectedItems.Properties[i].Values) { int counter = 1; while (ok && currRow[counter] != null) { if (currRow[counter].value == propValue) { break; } else { if (currRow.Count == (counter + 1) || currRow[counter].value == "") { ok = false; } } ++counter; } if (!ok) { break; } } break; } else { if (currRow.Next == null) { ok = false; } currRow = currRow.Next; } } if (!ok) { break; } } if (ok) { ids.Add(product.Id); } } return(PartialView("Partials/ProductList", ids)); } catch { return(PartialView("Partials/ProductList", new List <int>())); } }