protected SpecificationAttributeOptionFilterCollection getAlreadyFilteredSpecs()
        {
            var result = new SpecificationAttributeOptionFilterCollection();

            string[] queryStringParams = getAlreadyFilteredSpecsQueryStringParams();
            foreach (string qsp in queryStringParams)
            {
                int id = 0;
                int.TryParse(Request.QueryString[qsp], out id);
                var sao = SpecificationAttributeManager.GetSpecificationAttributeOptionById(id);
                if (sao != null)
                {
                    var sa = sao.SpecificationAttribute;
                    if (sa != null)
                    {
                        result.Add(new SpecificationAttributeOptionFilter
                        {
                            SpecificationAttributeId   = sa.SpecificationAttributeId,
                            SpecificationAttributeName = sa.Name,
                            DisplayOrder = sa.DisplayOrder,
                            SpecificationAttributeOptionId   = sao.SpecificationAttributeOptionId,
                            SpecificationAttributeOptionName = sao.Name
                        });
                    }
                }
            }

            return(result);
        }
        protected SpecificationAttributeOptionFilterCollection getNotFilteredSpecs()
        {
            //get all
            SpecificationAttributeOptionFilterCollection result = SpecificationAttributeManager.GetSpecificationAttributeOptionFilter(this.CategoryID);

            //remove already filtered
            SpecificationAttributeOptionFilterCollection alreadyFilteredOptions = getAlreadyFilteredSpecs();

            foreach (SpecificationAttributeOptionFilter saof1 in alreadyFilteredOptions)
            {
                var query = from s
                            in result
                            where s.SpecificationAttributeID == saof1.SpecificationAttributeID
                            select s;

                List <SpecificationAttributeOptionFilter> toRemove = query.ToList();

                foreach (SpecificationAttributeOptionFilter saof2 in toRemove)
                {
                    result.Remove(saof2);
                }
            }

            result.RemoveAll(x => excludeFilteredOptions.Contains(x.SpecificationAttributeName.ToLower()));
            result.Sort(new SpecificationAttributeOptionFilterComparer());
            return(result);
        }
        /// <summary>
        /// Gets a filtered product specification attribute mapping collection by category id
        /// </summary>
        /// <param name="categoryID">Product category identifier</param>
        /// <returns>Product specification attribute mapping collection</returns>
        public static SpecificationAttributeOptionFilterCollection GetSpecificationAttributeOptionFilter(int CategoryID)
        {
            DBSpecificationAttributeOptionFilterCollection dbCol = DBProviderManager <DBSpecificationAttributeProvider> .Provider.GetSpecificationAttributeOptionFilterByCategoryID(CategoryID);

            SpecificationAttributeOptionFilterCollection col = DBMapping(dbCol);

            return(col);
        }
        public List <int> GetAlreadyFilteredSpecOptionIDs()
        {
            List <int> result = new List <int>();
            SpecificationAttributeOptionFilterCollection filterOptions = getAlreadyFilteredSpecs();

            foreach (SpecificationAttributeOptionFilter saof in filterOptions)
            {
                if (!result.Contains(saof.SpecificationAttributeOptionID))
                {
                    result.Add(saof.SpecificationAttributeOptionID);
                }
            }
            return(result);
        }
        /// <summary>
        /// Maps a DBSpecificationAttributeOptionFilterCollection to a SpecificationAttributeOptionFilterCollection
        /// </summary>
        /// <param name="dbCol">DBSpecificationAttributeOptionFilterCollection</param>
        /// <returns>SpecificationAttributeOptionFilterCollection</returns>
        private static SpecificationAttributeOptionFilterCollection DBMapping(DBSpecificationAttributeOptionFilterCollection dbCol)
        {
            if (dbCol == null)
            {
                return(null);
            }

            SpecificationAttributeOptionFilterCollection col = new SpecificationAttributeOptionFilterCollection();

            foreach (DBSpecificationAttributeOptionFilter dbItem in dbCol)
            {
                SpecificationAttributeOptionFilter item = DBMapping(dbItem);
                col.Add(item);
            }
            return(col);
        }
        protected void BindData()
        {
            SpecificationAttributeOptionFilterCollection alreadyFilteredOptions = getAlreadyFilteredSpecs();
            SpecificationAttributeOptionFilterCollection notFilteredOptions     = getNotFilteredSpecs();

            if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
            {
                if (alreadyFilteredOptions.Count > 0)
                {
                    rptAlreadyFilteredPSO.DataSource = alreadyFilteredOptions;
                    rptAlreadyFilteredPSO.DataBind();

                    String navigateUrl = CommonHelper.GetThisPageURL(false);
                    bool   first       = true;
                    foreach (var key in Request.QueryString.Keys)
                    {
                        if (key == null)
                        {
                            continue;
                        }

                        string skey = key.ToString();
                        if (excludeParamsForFilter.Contains(skey))
                        {
                            if (first)
                            {
                                navigateUrl += "?";
                                first        = false;
                            }
                            else
                            {
                                navigateUrl += "&";
                            }

                            navigateUrl += key + "=" + CommonHelper.QueryStringInt(key.ToString());
                        }
                    }

                    hlRemoveFilter.NavigateUrl = navigateUrl;
                }
                else
                {
                    pnlAlreadyFilteredPSO.Visible = false;
                    pnlRemoveFilter.Visible       = false;
                }

                if (notFilteredOptions.Count > 0)
                {
                    rptFilterByPSO.DataSource = notFilteredOptions;
                    rptFilterByPSO.DataBind();
                }
                else
                {
                    pnlPSOSelector.Visible = false;
                }
            }
            else
            {
                Visible = false;
            }
        }