Beispiel #1
0
 public ProductProcessor(IProductApiClient apiClient, IProductFilter productFilter,
                         IProductHighlighter productHighlighter)
 {
     _apiClient          = apiClient;
     _productFilter      = productFilter;
     _productHighlighter = productHighlighter;
 }
Beispiel #2
0
 public ProductService(DoggyFoodyDatabaseContext dbContext, IUserService userService, IProductFilter productFilter, IColumnService columnService)
 {
     _dbContext     = dbContext;
     _userService   = userService;
     _filter        = productFilter;
     _columnService = columnService;
 }
Beispiel #3
0
 public ProductCrudSubService(IProductMapperService productMapperService,
                              IProductFilter productFilter,
                              IProductDomainService productDomainService)
 {
     this.productMapperService = productMapperService;
     this.productFilter        = productFilter;
     this.productDomainService = productDomainService;
 }
		public async Task<IEnumerable<IProduct>> FetchProducts(int pageSize, int offset, IProductFilter filter = null)
		{
			using (var tokenSource = new CancellationTokenSource(Constants.FetchProductsTimeout))
			{
				var result = await FindProducts("", pageSize, offset, filter);
				return result;
			}
		}
		public async Task<IEnumerable<IProduct>> FindProducts(string query, int pageSize, int offset, IProductFilter filter = null)
		{
			using (var tokenSource = new CancellationTokenSource(Constants.FindProductsTimeout))
			{				
				var algoliaQuery = new Algolia.Search.Query(query);
				algoliaQuery = getFilteredProductQuery(algoliaQuery, filter);
				if (pageSize > 0)
				{
					algoliaQuery.SetNbHitsPerPage(pageSize);
				}
				if (offset > 0)
				{
					algoliaQuery.SetPage(offset / pageSize);
				}

				var result = await _productIndex.SearchAsync(algoliaQuery, tokenSource.Token);
				var products = result["hits"].ToObject<List<Product>>();
				await GetProductCategoryFacets(query, filter);
				return products;
			}
		}
 public FilteredProducts FilterProducts(IProductFilter filter)
 {
     // execute the filter
     // return the products
 }
 /// <summary>
 /// Adds a constraint by a <see cref="IProductFilter"/>.
 /// </summary>
 /// <param name="builder">
 /// The builder.
 /// </param>
 /// <param name="filter">
 /// The filter.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContentQueryBuilder"/>.
 /// </returns>
 public static IProductContentQueryBuilder ConstrainBy(this IProductContentQueryBuilder builder, IProductFilter filter)
 {
     builder.AddConstraint(filter);
     return builder;
 }
		private async Task<Dictionary<string, int>> getProductAttributeFacets(string query, string facetAttribute, IProductFilter filter = null, params string[] childFacets)
		{
			var algoliaQuery = new Algolia.Search.Query(query);
			algoliaQuery = getFilteredProductQuery(algoliaQuery, filter, new string[] {facetAttribute}.Concatenate(childFacets));
			algoliaQuery.SetNbHitsPerPage(0);
			algoliaQuery.SetFacets(new string[] {facetAttribute});
			var result = await _productIndex.SearchAsync(algoliaQuery);
			try
			{
				var facets = result["facets"][facetAttribute].ToObject<Dictionary<string, int>>();
				return facets;
			}
			catch
			{
			}
			return null;
		}
		private Algolia.Search.Query getFilteredProductQuery(Algolia.Search.Query query, IProductFilter filter, params string[] excludeFacets )
		{
			if (filter != null)
			{
				List<string> facets = new List<string>();
				facets.Add("status:"+(int)ProductStatus.Approved);
				facets.Add("notVisible:false");
				facets.Add("isBlocked:false");
				if (filter.Category != null && !excludeFacets.Contains("categoryID"))
				{
					facets.Add("categoryID:"+filter.Category.ID);
				}

				if (filter.Subcategory != null && !excludeFacets.Contains("subcategoryID"))
				{
					facets.Add("subcategoryID:"+filter.Subcategory.ID);
				}

				if (filter.Country != null && !excludeFacets.Contains("countryID"))
				{
					facets.Add("countryID:"+filter.Country.ID);
				}

				if (filter.City != null && !excludeFacets.Contains("cityID"))
				{
					facets.Add("cityID:"+filter.City.ID);
				}

				if (facets.Count > 0)
					query.SetFacetFilters(facets);

				if (filter.Tags != null && filter.Tags.Count > 0)
				{
					query.SetTagFilters(string.Join(",", filter.Tags));
				}

				List<string> numericFilters = new List<string>();
				numericFilters.Add("status=" + (int)ProductStatus.Approved);

				if (filter.StartPrice != null)
				{
					numericFilters.Add("price>=" + filter.StartPrice);
				}

				if (filter.EndPrice != null)
				{
					numericFilters.Add("price<=" + filter.EndPrice);
				}

				if (numericFilters.Count > 0)
					query.SetNumericFilters(string.Join(",", numericFilters));
			}
			return query;
		}
		private ParseQuery<ParseProduct> getFilteredProductQuery(ParseQuery<ParseProduct> query, IProductFilter filter)
		{
			if (filter != null)
			{
				if (filter.Category != null)
				{
					query = query.Where(p => p.Category == ParseObject.CreateWithoutData<ParseProductCategory>(filter.Category.ID));
				}

				if (filter.Subcategory != null)
				{
					query = query.Where(p => p.Subcategory == ParseObject.CreateWithoutData<ParseProductSubcategory>(filter.Subcategory.ID));
				}

				if (filter.Country != null)
				{
					query = query.Where(p => p.Country == ParseObject.CreateWithoutData<ParseCountry>(filter.Country.ID));
				}

				if (filter.City != null)
				{
					query = query.Where(p => p.City == ParseObject.CreateWithoutData<ParseCity>(filter.City.ID));
				}

				if (filter.Tags != null && filter.Tags.Count > 0)
				{
					query = getContainsAllQuery(query, "tags", filter.Tags);
				}

				if (filter.StartPrice != null)
				{
					query = query.Where(p => p.Price >= filter.StartPrice.Value);
				}

				if (filter.EndPrice != null)
				{
					query = query.Where(p => p.Price <= filter.EndPrice.Value);
				}
			}
			return query;
		}
		public async Task<Dictionary<string, int>> GetProductCityFacets(string query, IProductFilter filter = null)
		{
			var result = await getProductAttributeFacets(query, "cityID", filter);
			return result;
		}
		public async Task<int> CountProducts(string query, IProductFilter filter = null)
		{
			var algoliaQuery = new Algolia.Search.Query(query);
			algoliaQuery = getFilteredProductQuery(algoliaQuery, filter);
			algoliaQuery.SetNbHitsPerPage(0);
			var result = await _productIndex.SearchAsync(algoliaQuery);
			try
			{
				var count = result["nbHits"].ToObject<int>();
				return count;
			}
			catch
			{
			}
			return -1;
		}
 /// <summary>
 /// Adds a constraint by a <see cref="IProductFilter"/>.
 /// </summary>
 /// <param name="builder">
 /// The builder.
 /// </param>
 /// <param name="filter">
 /// The filter.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContentQueryBuilder"/>.
 /// </returns>
 public static IProductContentQueryBuilder ConstrainBy(this IProductContentQueryBuilder builder, IProductFilter filter)
 {
     builder.AddConstraint(filter);
     return(builder);
 }
		public ProductFilterChangedMessage(object sender, IProductFilter productFilter)
			: base(sender)
		{
			ProductFilter = productFilter;
		}
Beispiel #15
0
 public ProductsController(Data data, IProductFilter filter)
 {
     myProducts    = data.Products;
     productFilter = filter;
 }