protected void gvProducts_Sorting(object sender, GridViewSortEventArgs e)
        {
            ProductSortingType orderBy = ProductSortingType.IdAsc;

            switch (e.SortExpression)
            {
            case "Name":
                orderBy = ProductSortingType.NameDesc;
                if (e.SortDirection == SortDirection.Ascending)
                {
                    orderBy = ProductSortingType.NameAsc;
                }
                break;

            case "Id":
            default:
                orderBy = ProductSortingType.IdDesc;
                if (e.SortDirection == SortDirection.Ascending)
                {
                    orderBy = ProductSortingType.IdAsc;
                }
                break;
            }

            SetState("OrderBy", (int)orderBy);
            LoadProducts();
        }
示例#2
0
        public string ConvertEnum(ProductSortingType type)
        {
            switch (type)
            {
            case ProductSortingType.NameAsc:
                return("Name: A to Z");

            case ProductSortingType.NameDesc:
                return("Name: Z to A");

            case ProductSortingType.PriceAsc:
                return("Price: Low to High");

            case ProductSortingType.PriceDesc:
                return("Price: High to Low");

            case ProductSortingType.CreatedOn:
                return("Recently Added");

            case ProductSortingType.ReviewScoreDesc:
                return("Top Rated");

            case ProductSortingType.StockDesc:
                return("Stock Level");

            case ProductSortingType.Position:
                return("Default");

            default:
                return(string.Empty);
            }
        }
        private void LoadProducts()
        {
            int[]              productIds = null;
            string             name       = null;
            ProductSortingType orderBy    = ProductSortingType.NameAsc;

            if (HasState("OrderBy"))
            {
                orderBy = (ProductSortingType)GetIntState("OrderBy");
            }
            if (HasState("testproductidfilter"))
            {
                string value = GetStringState("testproductidfilter");
                int    temp;
                productIds = value.Split(',')
                             .Where(x => int.TryParse(x.ToString(), out temp))
                             .Select(x => int.Parse(x))
                             .ToArray();
            }
            if (HasState("testproductnamefilter"))
            {
                name = GetStringState("testproductnamefilter");
            }

            var result = ProductService.GetPagedProductOverviewModel(
                pageIndex: gvTestProducts.CustomPageIndex,
                pageSize: gvTestProducts.PageSize,
                productIds: productIds,
                keywords: name,
                orderBy: orderBy);

            if (result != null)
            {
                gvTestProducts.DataSource      = result.Items;
                gvTestProducts.RecordCount     = result.TotalCount;
                gvTestProducts.CustomPageCount = result.TotalPages;
            }

            gvTestProducts.DataBind();

            if (gvTestProducts.Rows.Count <= 0)
            {
                enbTestProducts.Message = "No records found.";
            }
        }
        protected void gvRelatedProductSelector_Sorting(object sender, GridViewSortEventArgs e)
        {
            ProductSortingType orderBy = ProductSortingType.IdAsc;

            switch (e.SortExpression)
            {
            case "Id":
            default:
                orderBy = ProductSortingType.IdDesc;
                if (e.SortDirection == SortDirection.Ascending)
                {
                    orderBy = ProductSortingType.IdAsc;
                }
                break;
            }

            SetState("RelatedProduct-OrderBy", (int)orderBy);
            LoadProductsForRelatedProductSelector();
        }
示例#5
0
        public SearchResultPagedList <ProductOverviewModel> SearchProduct(
            int pageIndex                      = 0,
            int pageSize                       = int.MaxValue,
            IList <int> categoryIds            = null,
            IList <int> brandIds               = null,
            IList <int> productIds             = null,
            bool?enabled                       = default(bool?),
            bool?discontinued                  = default(bool?),
            bool?visibleIndividually           = default(bool?),
            bool includeDiscontinuedButInStock = false,
            decimal?priceMin                   = default(decimal?),
            decimal?priceMax                   = default(decimal?),
            string keywords                    = null,
            bool searchDescriptions            = false,
            bool useFullTextSearch             = false,
            FulltextSearchMode fullTextMode    = FulltextSearchMode.Or,
            bool applySearchAnalysis           = false,
            ProductSortingType orderBy         = ProductSortingType.Position,
            bool applyKeywordSuggestion        = false,
            bool displaySearchAnalysis         = false)
        {
            string suggestedKeywords = null;

            if (!string.IsNullOrEmpty(keywords))
            {
                // First, we check for search term
                var searchTerm = GetSearchTermByQuery(keywords);
                if (searchTerm != null)
                {
                    return(new SearchResultPagedList <ProductOverviewModel>(searchTerm));
                }

                // Then, we check for product name
                var product = _productService.GetActiveProductOverviewModelByName(keywords);
                if (product != null)
                {
                    return(new SearchResultPagedList <ProductOverviewModel>(new List <ProductOverviewModel> {
                        product
                    }));
                }

                suggestedKeywords = keywords;

                if (applyKeywordSuggestion == true && !string.IsNullOrWhiteSpace(keywords))
                {
                    // We check if it's a brand name
                    var   suggestionBrands = _spellCheckerService.Suggest(keywords);
                    Brand brand            = null;

                    if (suggestionBrands.Count > 0)
                    {
                        brand = _brandService.GetBrandByName(suggestionBrands[0]);
                        if (brand != null)
                        {
                            suggestedKeywords = suggestionBrands[0];
                            if (brandIds == null)
                            {
                                brandIds = new List <int> {
                                    brand.Id
                                }
                            }
                            ;
                            else
                            {
                                brandIds.Add(brand.Id);
                            }
                        }
                    }

                    if (brand == null)
                    {
                        var words = keywords.Split(' ');

                        for (int i = 0; i < words.Length; i++)
                        {
                            bool correct = _spellCheckerService.Spell(words[i]);

                            if (!correct)
                            {
                                var suggestions = _spellCheckerService.Suggest(words[i]);
                                if (suggestions.Count > 0)
                                {
                                    words[i] = suggestions[0];                        //Choose the first one.
                                }
                            }
                        }
                        suggestedKeywords = string.Join(" ", words);
                    }
                }
            }

            var list = _productService.GetPagedProductOverviewModel(
                pageIndex: pageIndex,
                pageSize: pageSize,
                categoryIds: categoryIds,
                brandIds: brandIds,
                productIds: productIds,
                enabled: enabled,
                discontinued: discontinued,
                visibleIndividually: visibleIndividually,
                includeDiscontinuedButInStock: includeDiscontinuedButInStock,
                priceMin: priceMin,
                priceMax: priceMax,
                //keywords: applyKeywordSuggestion ? suggestedKeywords : keywords,
                keywords: keywords,
                searchDescriptions: searchDescriptions,
                useFullTextSearch: useFullTextSearch,
                fullTextMode: fullTextMode,
                applySearchAnalysis: applySearchAnalysis,
                orderBy: orderBy,
                displaySearchAnalysis: displaySearchAnalysis);

            if (string.IsNullOrEmpty(suggestedKeywords) == false && suggestedKeywords.ToLower().CompareTo(keywords.ToLower()) == 0)
            {
                suggestedKeywords = null;
            }

            var result = new SearchResultPagedList <ProductOverviewModel>(
                list.Items, list.PageIndex, list.PageSize, list.TotalCount, suggestedKeywords,
                list.MaxPriceFilterByKeyword, list.MinPriceFilterByKeyword);

            return(result);
        }
        private void LoadProducts()
        {
            int[]  productIds = null;
            string name       = null;

            int[] brandIds             = null;
            int[] categoryIds          = null;
            ProductSortingType orderBy = ProductSortingType.NameAsc;

            if (HasState("OrderBy"))
            {
                orderBy = (ProductSortingType)GetIntState("OrderBy");
            }
            if (HasState(PRODUCT_ID_FILTER))
            {
                string value = GetStringState(PRODUCT_ID_FILTER);
                int    temp;
                productIds = value.Split(',')
                             .Where(x => int.TryParse(x.ToString(), out temp))
                             .Select(x => int.Parse(x))
                             .ToArray();
            }
            if (HasState(BRAND_ID_FILTER))
            {
                string value = GetStringState(BRAND_ID_FILTER);
                int    temp;
                brandIds = value.Split(',')
                           .Where(x => int.TryParse(x.ToString(), out temp))
                           .Select(x => int.Parse(x))
                           .ToArray();
            }
            if (HasState(CATEGORY_ID_FILTER))
            {
                string value = GetStringState(CATEGORY_ID_FILTER);
                int    temp;
                categoryIds = value.Split(',')
                              .Where(x => int.TryParse(x.ToString(), out temp))
                              .Select(x => int.Parse(x))
                              .ToArray();
            }

            if (HasState(NAME_FILTER))
            {
                name = GetStringState(NAME_FILTER);
            }

            var result = ProductService.GetPagedProductOverviewModel(
                pageIndex: gvProducts.CustomPageIndex,
                pageSize: gvProducts.PageSize,
                brandIds: brandIds,
                categoryIds: categoryIds,
                productIds: productIds,
                keywords: name,
                orderBy: orderBy);

            if (result != null)
            {
                gvProducts.DataSource      = result.Items;
                gvProducts.RecordCount     = result.TotalCount;
                gvProducts.CustomPageCount = result.TotalPages;
            }

            gvProducts.DataBind();

            if (gvProducts.Rows.Count <= 0)
            {
                enbProducts.Message = "No records found.";
            }
        }
示例#7
0
        private void LoadProducts()
        {
            int[]              productIds   = null;
            string             name         = null;
            bool?              enabled      = null;
            bool?              discontinued = null;
            ProductSortingType orderBy      = ProductSortingType.NameAsc;

            if (HasState(PRODUCT_ID_FILTER))
            {
                string value = GetStringState(PRODUCT_ID_FILTER);
                int    temp;
                productIds = value.Split(',')
                             .Where(x => int.TryParse(x.ToString(), out temp))
                             .Select(x => int.Parse(x))
                             .ToArray();
            }
            if (HasState(PRODUCT_NAME_FILTER))
            {
                name = GetStringState(PRODUCT_NAME_FILTER);
            }
            if (GetStringState(STATUS_FILTER) == ENABLED)
            {
                enabled = true;
            }
            if (GetStringState(STATUS_FILTER) == DISABLED)
            {
                enabled = false;
            }
            if (GetStringState(DISCONTINUED_FILTER) == ENABLED)
            {
                discontinued = true;
            }
            if (GetStringState(DISCONTINUED_FILTER) == DISABLED)
            {
                discontinued = false;
            }
            if (HasState("OrderBy"))
            {
                orderBy = (ProductSortingType)GetIntState("OrderBy");
            }

            var result = ProductService.GetPagedProductOverviewModel(
                pageIndex: gvProducts.CustomPageIndex,
                pageSize: gvProducts.PageSize,
                productIds: productIds,
                keywords: name,
                enabled: enabled,
                discontinued: discontinued,
                orderBy: orderBy);

            if (result != null)
            {
                gvProducts.DataSource      = result.Items;
                gvProducts.RecordCount     = result.TotalCount;
                gvProducts.CustomPageCount = result.TotalPages;
            }

            gvProducts.DataBind();

            if (gvProducts.Rows.Count <= 0)
            {
                enbNotice.Message = "No records found.";
            }
        }