Пример #1
0
 public ProductListModel Execute(ProductCriteriaModel productCriteria)
 {
     using (_uowFactory.BeginReadOnlyUow())
     {
         return(_getProductsDataQuery.Execute(productCriteria));
     }
 }
Пример #2
0
        public async Task <List <ProductModel> > GeneralFilterAsync(ProductCriteriaModel criteria)
        {
            var products = _context.Products.AsQueryable().AsNoTracking();

            if (criteria != null)
            {
                if (!String.IsNullOrWhiteSpace(criteria.SearchString))
                {
                    products = products.Where(prod => prod.Name.Contains(criteria.SearchString));
                }

                if (criteria.CategoryId.HasValue)
                {
                    products = products.Where(prod => prod.CategoryId == criteria.CategoryId);
                }

                if (criteria.MinValue >= 0 && criteria.MaxValue > 0)
                {
                    products = products.Where(prod => prod.Price >= criteria.MinValue && prod.Price <= criteria.MaxValue);
                }
            }

            return(await products
                   .Select(productModel => new ProductModel
            {
                Id = productModel.Id,
                Name = productModel.Name,
                Price = productModel.Price,
                Count = productModel.Count,
                SKU = productModel.SKU,
                CategoryId = productModel.CategoryId,
                CategoryName = productModel.Category.Name
            })
                   .ToListAsync());
        }
Пример #3
0
        public ProductListModel Execute(ProductCriteriaModel productCriteria)
        {
            IDbConnection        connection = _ambientUowProvider.Get <IDbConnection>();
            string               sql        = "SELECT * FROM Product;";
            List <ProductEntity> products   = connection.Query <ProductEntity>(sql).AsList();
            var productListModel            = new ProductListModel
            {
                Products = _mapper.Map <IEnumerable <ProductModel> >(products)
            };

            return(productListModel);
        }