Ejemplo n.º 1
0
        private void StoreAllProductTagsInCache(ProductsQueryRequest queryRequest)
        {
            var tags           = _productRepository.GetProductTags(queryRequest.Keyword, queryRequest.Category);
            var productSizeDto = Mapper.Map <IList <ProductTag>, IList <ProductTagDto> >(tags);

            _cacheManager.Store(CachingConstant.PrductTags, productSizeDto, CachingConstant.MemoryCacheTime);
        }
Ejemplo n.º 2
0
        public ProductTagsQueryResponse GetPrductTags(ProductsQueryRequest queryRequest)
        {
            var response = new ProductTagsQueryResponse();

            try
            {
                var productTagDto = _cacheManager.Retrieve <IList <ProductTagDto> >(CachingConstant.PrductTags);

                if (productTagDto != null)
                {
                    response.Tags = string.IsNullOrWhiteSpace(queryRequest.Keyword)
                        ? productTagDto.ToList()
                        : productTagDto.Where(t => t.Name.Contains(queryRequest.Keyword)).ToList();
                }

                var productTag = _productRepository.GetProductTags(queryRequest.Keyword, queryRequest.Category);
                productTagDto = Mapper.Map <IList <ProductTag>, IList <ProductTagDto> >(productTag);
                response.Tags = productTagDto;
                StoreAllProductTagsInCache(queryRequest);
            }
            catch (Exception exception)
            {
                response.Failed = true;
                _logger.Log(exception.Message);
            }

            return(response);
        }
Ejemplo n.º 3
0
        public ProductsQueryResponse SearchInProducts(ProductsQueryRequest request)
        {
            var response = new ProductsQueryResponse();

            try
            {
                var products = _productRepository.SearchInProducts(request, request.Category);

                if (products == null)
                {
                    response.Message = ProductQueryMessage.NoResultFound;
                    return(response);
                }

                response.Products = Mapper.Map <PagingQueryResponse <Product>, PagingQueryResponse <ProductDto> >(products);
            }
            catch (Exception exception)
            {
                _logger.Error(exception.Message);
            }

            return(response);
        }
Ejemplo n.º 4
0
        public ProductsQueryResponse GetSpecialProducts(ProductsQueryRequest request)
        {
            var response = new ProductsQueryResponse();

            try
            {
                var products = _productRepository.GetSpecialProducts(request);

                if (products == null)
                {
                    response.Message = ProductQueryMessage.NoSpecialProductFound;
                    return(response);
                }

                response.Products = Mapper.Map <PagingQueryResponse <Product>, PagingQueryResponse <ProductDto> >(products);
            }
            catch (Exception exception)
            {
                _logger.Error(exception.Message);
                response.Message = QueryMessage.RetrievingFailed;
            }

            return(response);
        }
Ejemplo n.º 5
0
        public ProductsQueryResponse GetProductsByStore(ProductsQueryRequest request)
        {
            var response = new ProductsQueryResponse();

            try
            {
                var products = _productRepository.GetProductsByStore(request, request.StoreId);

                if (products == null)
                {
                    response.Message = ProductQueryMessage.NoProductFoundForTheStore;
                    return(response);
                }

                response.Products = Mapper.Map <PagingQueryResponse <Product>, PagingQueryResponse <ProductDto> >(products);
            }
            catch (Exception exception)
            {
                response.Failed = true;
                _logger.Log(exception.Message);
            }

            return(response);
        }
Ejemplo n.º 6
0
        public ProductsQueryResponse GetProductsByTag(ProductsQueryRequest request)
        {
            var response = new ProductsQueryResponse();

            try
            {
                var products = _productRepository.GetProductsByTag(request, request.Category, request.Tag);

                if (products == null)
                {
                    response.Message = ProductQueryMessage.NoProductFoundForTheTag;
                    return(response);
                }

                response.Products = Mapper.Map <PagingQueryResponse <Product>, PagingQueryResponse <ProductDto> >(products);
            }
            catch (Exception exception)
            {
                _logger.Error(exception.Message);
                response.Message = QueryMessage.RetrievingFailed;
            }

            return(response);
        }