Exemplo n.º 1
0
        public override ProductInfosAndCount GetProductInformationsByProductFilter(ProductFilterInfo filter)
        {
            IQueryable <Product> products = context.Products;

            if (filter.CategoryId.HasValue)
            {
                products = FilterByCategory(products, filter.CategoryId.Value);
            }

            if (filter.IntProps != null && filter.IntProps.Any())
            {
                products = FilterByIntProps(products, filter.IntProps);
            }

            if (filter.DecimalProps != null && filter.DecimalProps.Any())
            {
                products = FilterByDecimalProps(products, filter.DecimalProps);
            }

            if (filter.StringProps != null && filter.StringProps.Any())
            {
                products = FilterByStringProps(products, filter.StringProps);
            }

            if (!string.IsNullOrWhiteSpace(filter.SearchTerm))
            {
                products = FilterBySearch(products, filter.SearchTerm);
            }

            if (filter.OrderBy == OrderBy.Property && !filter.SortingPropertyId.HasValue)
            {
                throw new ArgumentException("Sorting property must have value");
            }

            products = OrderProducts(products, filter.OrderBy, filter.SortingPropertyId, filter.SortAscending);

            return(new ProductInfosAndCount
            {
                Count = products.Count(),
                Infos = products.Skip(filter.Skip).Take(filter.Quantity).Select(p => p.Info).ToList()
            });
        }
Exemplo n.º 2
0
        public ProductInfosAndCount ByFilter([FromBody] ProductFilterInfo filter)
        {
            var result = (repository as ProductRepository).GetProductInformationsByProductFilter(filter);

            return(result);
        }
Exemplo n.º 3
0
 public abstract ProductInfosAndCount GetProductInformationsByProductFilter(ProductFilterInfo filter);