Beispiel #1
0
        /// <summary>
        /// Search products count
        /// </summary>
        public virtual IEnumerable <int> GetPriceAmountForFilter(Filter filter)
        {
            //validate "categoryIds" parameter
            if (filter.CategoryIds != null && filter.CategoryIds.Contains(0))
            {
                filter.CategoryIds.Remove(0);
            }

            //pass category identifiers as comma-delimited string
            string commaSeparatedCategoryIds = "";

            if (filter.CategoryIds != null)
            {
                for (int i = 0; i < filter.CategoryIds.Count; i++)
                {
                    commaSeparatedCategoryIds += filter.CategoryIds[i].ToString();
                    if (i != filter.CategoryIds.Count - 1)
                    {
                        commaSeparatedCategoryIds += ",";
                    }
                }
            }

            string commaSeparatedSpecIds = "";

            if (filter.AlreadyFilteredSpecOptionIds != null)
            {
                ((List <int>)filter.AlreadyFilteredSpecOptionIds).Sort();
                for (int i = 0; i < filter.AlreadyFilteredSpecOptionIds.Count; i++)
                {
                    commaSeparatedSpecIds += filter.AlreadyFilteredSpecOptionIds[i].ToString();
                    if (i != filter.AlreadyFilteredSpecOptionIds.Count - 1)
                    {
                        commaSeparatedSpecIds += ",";
                    }
                }
            }

            //prepare parameters
            var pCategoryIds = _dataProvider.GetParameter();

            pCategoryIds.ParameterName = "CategoryIds";
            pCategoryIds.Value         = (object)commaSeparatedCategoryIds;
            pCategoryIds.DbType        = DbType.String;

            var pFilteredSpecs = _dataProvider.GetParameter();

            pFilteredSpecs.ParameterName = "FilteredSpecs";
            pFilteredSpecs.Value         = (object)commaSeparatedSpecIds;
            pFilteredSpecs.DbType        = DbType.String;

            var pShowWithPositiveQuantity = _dataProvider.GetParameter();

            pShowWithPositiveQuantity.ParameterName = "ShowWithPositiveQuantity";
            pShowWithPositiveQuantity.Value         = filter.ShowWithPositiveQuantity;
            pShowWithPositiveQuantity.DbType        = DbType.Boolean;


            //invoke stored procedure
            var prices = _dbContext.ExecuteStoredProcedureListWithoutAttach <int>(
                "GetPriceAmountForFilter",
                pCategoryIds,
                pFilteredSpecs,
                pShowWithPositiveQuantity);


            return(prices);
        }
        /// <summary>
        /// Search products count
        /// </summary>
        public virtual IEnumerable <SpecificationAttributeOptionWithCount> SearchProductsCount(
            out int positiveQuantityCount,
            IList <int> categoryIds       = null,
            bool?featuredProducts         = null,
            decimal?priceMin              = null,
            decimal?priceMax              = null,
            IList <int> filteredSpecs     = null,
            bool showWithPositiveQuantity = false)
        {
            //validate "categoryIds" parameter
            if (categoryIds != null && categoryIds.Contains(0))
            {
                categoryIds.Remove(0);
            }

            //pass category identifiers as comma-delimited string
            string commaSeparatedCategoryIds = "";

            if (categoryIds != null)
            {
                for (int i = 0; i < categoryIds.Count; i++)
                {
                    commaSeparatedCategoryIds += categoryIds[i].ToString();
                    if (i != categoryIds.Count - 1)
                    {
                        commaSeparatedCategoryIds += ",";
                    }
                }
            }

            string commaSeparatedSpecIds = "";

            if (filteredSpecs != null)
            {
                ((List <int>)filteredSpecs).Sort();
                for (int i = 0; i < filteredSpecs.Count; i++)
                {
                    commaSeparatedSpecIds += filteredSpecs[i].ToString();
                    if (i != filteredSpecs.Count - 1)
                    {
                        commaSeparatedSpecIds += ",";
                    }
                }
            }

            //prepare parameters
            var pCategoryIds = _dataProvider.GetParameter();

            pCategoryIds.ParameterName = "CategoryIds";
            pCategoryIds.Value         = (object)commaSeparatedCategoryIds;
            pCategoryIds.DbType        = DbType.String;

            var pPriceMin = _dataProvider.GetParameter();

            pPriceMin.ParameterName = "PriceMin";
            pPriceMin.Value         = priceMin.HasValue ? (object)priceMin.Value : DBNull.Value;
            pPriceMin.DbType        = DbType.Decimal;

            var pPriceMax = _dataProvider.GetParameter();

            pPriceMax.ParameterName = "PriceMax";
            pPriceMax.Value         = priceMax.HasValue ? (object)priceMax.Value : DBNull.Value;
            pPriceMax.DbType        = DbType.Decimal;

            var pFilteredSpecs = _dataProvider.GetParameter();

            pFilteredSpecs.ParameterName = "FilteredSpecs";
            pFilteredSpecs.Value         = (object)commaSeparatedSpecIds;
            pFilteredSpecs.DbType        = DbType.String;

            var pShowWithPositiveQuantity = _dataProvider.GetParameter();

            pShowWithPositiveQuantity.ParameterName = "ShowWithPositiveQuantity";
            pShowWithPositiveQuantity.Value         = showWithPositiveQuantity;
            pShowWithPositiveQuantity.DbType        = DbType.Boolean;

            var pPositiveQuantityCount = _dataProvider.GetParameter();

            pPositiveQuantityCount.ParameterName = "PositiveQuantityCount";
            pPositiveQuantityCount.Direction     = ParameterDirection.Output;
            pPositiveQuantityCount.DbType        = DbType.Int32;

            //invoke stored procedure
            var products = _dbContext.ExecuteStoredProcedureListWithoutAttach <SpecificationAttributeOptionWithCount>(
                "ProductLoadAllPaged2",
                pCategoryIds,
                pPriceMin,
                pPriceMax,
                pFilteredSpecs,
                pShowWithPositiveQuantity,
                pPositiveQuantityCount);

            positiveQuantityCount = (pPositiveQuantityCount.Value != DBNull.Value) ? Convert.ToInt32(pPositiveQuantityCount.Value) : 0;

            return(products);
        }