public ICollection <Product> GetByCriteria(ProductSearchCriteriaVM criteria)
        {
            var products = _db.Products.AsQueryable();

            if (criteria != null)
            {
                if (!string.IsNullOrEmpty(criteria.Name))
                {
                    products = products.Where(c => c.Name.ToLower().Contains(criteria.Name.ToLower()));
                }

                if (criteria.FromPrice > 0)
                {
                    products = products.Where(c => c.Price >= criteria.FromPrice);
                }

                if (criteria.ToPrice > 0)
                {
                    products = products.Where(c => c.Price <= criteria.ToPrice);
                }

                if (criteria.CategoryId > 0)
                {
                    products = products.Where(c => c.CategoryId == criteria.CategoryId);
                }
            }

            return(products.ToList());
        }
        public IActionResult Get([FromQuery] ProductSearchCriteriaVM criteria) //Just serach facilities GetByCriteria method
        {
            var products = _productManager.GetByCriteria(criteria);


            if (products != null && products.Any())
            {
                var productCreateViewModels = _mapper.Map <ICollection <ProductDto> >(products);
                return(Ok(productCreateViewModels));
            }

            return(NoContent());
            //.Select(p => new //if i want to show data like this format in browser then need this select option
            // {
            //     p.Id,
            //     p.Name,
            //     Category = new
            //     {
            //         CategoryId = p.Category.Id,
            //         CategoryName = p.Category.Name
            //     },
            //     p.IsActive,
            //     p.ExpireDate,
            //     p.Price,
            //     p.ImageUrl
            // });

            //if (products != null && products.Any())
            //{
            //    return Ok(products);
            //}
            //return NoContent();
        }
        public ICollection <Product> GetByCriteria(ProductSearchCriteriaVM criteria) //Just Implemented GetByCriteria method
        {
            var products = _db.Products.AsQueryable();

            if (criteria != null)
            {
                //AsQueryable working in database && AsEnumerable working in memory after pulling data from database.
                //AsQueryable using for generate query without hit to database.
                // AsQueryable means deferred execution
                //Imediate execution using when call(ToList(),foreach,_db.products etc)
                if (!string.IsNullOrEmpty(criteria.Name))                                               //criteria.Name != null && criteria.Name !="" = !string.IsNullOrEmpty(criteria.Name)
                {
                    products = products.Where(p => p.Name.ToLower().Contains(criteria.Name.ToLower())); //ToLower using for case insencetive
                }

                if (criteria.FromPrice > 0)
                {
                    products = products.Where(p => p.Price >= criteria.FromPrice);
                }

                if (criteria.ToPrice > 0)
                {
                    products = products.Where(p => p.Price <= criteria.ToPrice);
                }
            }
            return(products.ToList());//tolist using for imediate execution
        }
        public IActionResult Get([FromQuery] ProductSearchCriteriaVM criteria)
        {
            var products = _productManager.GetByCriteria(criteria);


            if (products != null && products.Any())
            {
                return(Ok(products));
            }

            return(NoContent());
        }
Beispiel #5
0
        public IActionResult Get([FromQuery] ProductSearchCriteriaVM criteria)
        {
            var products = _productManager.GetByCriteria(criteria);



            if (products != null && products.Any())
            {
                var productDtos = _mapper.Map <ICollection <ProductDto> >(products);
                return(Ok(productDtos));
            }

            return(NoContent());
        }
Beispiel #6
0
 public ICollection <Product> GetByCriteria(ProductSearchCriteriaVM criteria)
 {
     return(_productManger.GetByCriteria(criteria));
 }
 public ICollection <Product> GetByCriteria(ProductSearchCriteriaVM model) //Just Implemented GetByCriteria method
 {
     return(_productRepository.GetByCriteria(model));
 }
Beispiel #8
0
 public ICollection <Product> GetByCriteria(ProductSearchCriteriaVM criteria)
 {
     return(_productRepository.GetByCriteria(criteria));
 }