Пример #1
0
        public async Task <ProductCardAndBasketAndFilters> GetProductCardAndBasketAndFiltersAsync(FilterProductCard filters)
        {
            ProductCardAndBasketAndFilters result = new ProductCardAndBasketAndFilters
            {
                SearchEnumArray = searchEnumArray,
                SortEnumArray   = sortEnumArray,
                Filters         = filters
            };
            string             keyName      = $"ProductCards:{filters.GetFilterName()}";
            List <ProductCard> productCards = _cacheService.Get <List <ProductCard> >(keyName);

            if (productCards == null)
            {
                productCards = await _fcdStoreContext.GetProductCardsAsync(filters.SelectFromSelectList, (int)filters.CurrentPosition);

                result.ProductCards = productCards;
                _dataFiltering.Filtering(result);
                productCards = result.ProductCards;
                _cacheService.Set <List <ProductCard> >(keyName, result.ProductCards);
            }
            result.ProductCards = productCards;
            _dataFiltering.SetFilters(result);
            result.ProductCards     = _dataFiltering.Paginator <ProductCard>(result.ProductCards, (int)filters.CountVisablePositions, (int)filters.CurrentPosition);
            result.ProductsInBasket = await GetProductsInBasketAsync();

            result.SetBasketsCost();
            return(result);
        }
Пример #2
0
        public async Task <ProductCardAndBasketAndFilters> GetFilteringProductCardAndBasketAndFiltersAsync(FilterProductCard filters)
        {
            ProductCardAndBasketAndFilters result = new ProductCardAndBasketAndFilters
            {
                SearchEnumArray = searchEnumArray,
                SortEnumArray   = sortEnumArray,
                Filters         = filters
            };
            int    currentPosition          = (int)filters.CurrentPosition;
            string keyName                  = $"ProductCardsForSearch:{filters.GetFilterName()}",
                   desired                  = filters.Desired.ToLower();
            List <ProductCard> productCards = _cacheService.Get <List <ProductCard> >(keyName);

            if (productCards == null)
            {
                switch (Enum.Parse(typeWhereSearchProduct, filters.WhereSearch))
                {
                case (WhereSearch.По_названии):
                {
                    productCards = await _fcdStoreContext.GetProductCardsSearchNameAsync(desired, currentPosition);

                    break;
                }

                case (WhereSearch.В_атрибутах):
                {
                    productCards = await _fcdStoreContext.GetProductCardsSearchAttributesAsync(desired, currentPosition);

                    break;
                }

                case (WhereSearch.В_описании):
                {
                    productCards = await _fcdStoreContext.GetProductCardsSearchDescriptionsAsync(desired, currentPosition);

                    break;
                }

                case (WhereSearch.Везде):
                {
                    productCards = await _fcdStoreContext.GetProductCardsSearchAllAsync(desired, currentPosition);

                    break;
                }

                default:
                {
                    productCards = await _fcdStoreContext.GetProductCardsSearchNameAsync(desired, currentPosition);

                    break;
                }
                }
                result.ProductCards = productCards;
                _dataFiltering.Filtering(result);
                productCards = result.ProductCards;
                _cacheService.Set <List <ProductCard> >(keyName, productCards);
            }
            result.ProductCards = productCards;
            _dataFiltering.SetFilters(result);
            result.ProductCards     = _dataFiltering.Paginator <ProductCard>(result.ProductCards, (int)filters.CountVisablePositions, currentPosition);
            result.ProductsInBasket = await GetProductsInBasketAsync();

            result.SetBasketsCost();
            return(result);
        }