private string BuildInnerTabLink(MarketCenter marketcenter, string type)
        {
            StringBuilder innerLinkStringBuilder = new StringBuilder();
            string        HandledSeName          = "";

            innerLinkStringBuilder.Append("<li>");
            innerLinkStringBuilder.Append("<a id='a-mc-link-" + marketcenter.id + "' title='" + marketcenter.Name + "' ");

            if (marketcenter.childCompanies.Count > 0)
            {
                innerLinkStringBuilder.Append("class='mc-text-link box-handle' href='#window-offices-" + marketcenter.id + "' >");
            }
            else
            {
                if (!string.IsNullOrEmpty(type))
                {
                    HandledSeName = MarketCenterTypeURLHandle(marketcenter.SeName, type, marketcenter.id);
                }
                else
                {
                    HandledSeName = marketcenter.SeName;
                }

                innerLinkStringBuilder.Append("class='mc-text-link' href='" + HandledSeName + "' >");
            }

            innerLinkStringBuilder.Append(marketcenter.Name + "</a>");
            innerLinkStringBuilder.Append("</li>");

            return(innerLinkStringBuilder.ToString());;
        }
        private int GetChildCategories(int marketCenterCategoryId, string type, bool countOnly = false)
        {
            //child companies handling
            DataView marketCenterChildCompanyDataView = cacheManager.Get("marketCenterChildCompany" + marketCenterCategoryId, 60, () => {
                Dictionary <string, Object> marketCenterChildCompanyDic = new Dictionary <string, Object>();
                marketCenterChildCompanyDic.Add("@CategoryId", marketCenterCategoryId);

                string marketCenterChildCompanyDataQuery       = "EXEC usp_SelectGBSMarketCenterChildren @categoryId";
                DataView innerMarketCenterChildCompanyDataView = manager.GetParameterizedDataView(marketCenterChildCompanyDataQuery, marketCenterChildCompanyDic);

                return(innerMarketCenterChildCompanyDataView);
            });

            if (!countOnly)
            {
                if (marketCenterChildCompanyDataView.Count > 0)
                {
                    for (int i = 0; i < marketCenterChildCompanyDataView.Count; i++)
                    {
                        MarketCenter marketCenter = new MarketCenter(Int32.Parse(marketCenterChildCompanyDataView[i]["id"].ToString()), customType: type);
                        this.childCompanies.Add(marketCenter);
                    }
                }
            }

            return(marketCenterChildCompanyDataView.Count);
        }
        public Dictionary <string, string> GetMarketCenterHtml(string type, bool hack)
        {
            ICategoryService            categoryService          = EngineContext.Current.Resolve <ICategoryService>();
            Dictionary <string, string> marketCenterTabsDict     = new Dictionary <string, string>();
            List <MarketCenter>         featuredMarketCenterList = new List <MarketCenter>();
            List <MarketCenter>         alphaList1 = new List <MarketCenter>();
            List <MarketCenter>         alphaList2 = new List <MarketCenter>();
            List <MarketCenter>         alphaList3 = new List <MarketCenter>();

            //if top level and has children build popup with children links
            IList <Category> TopLevelMarketCenterIds = null;

            try
            {
                if (!hack)
                {
                    for (int i = 0; i < 20; i++)
                    //foreach (var marketcenterCategory in TopLevelMarketCenterIdsInOrder)
                    {
                        TopLevelMarketCenterIds = categoryService.GetAllCategoriesByParentCategoryId(this.id);

                        IList <Category> TopLevelMarketCenterIdsInOrder = TopLevelMarketCenterIds.OrderBy(c => c.Name).ToList();

                        MarketCenter marketcenter = null;


                        //TESTING !!!!!!!!!--------------------------------------------------------
                        //Random r = new Random();
                        //int v = r.Next(0, 2500); // to get random pool of market centers

                        //TESTING FOR FEATURED
                        //if (i == 0)
                        //{
                        //    marketcenter = new MarketCenter(1618, getChildren: true);
                        //}
                        //else if (i == 2)
                        //{
                        //    marketcenter = new MarketCenter(1461, getChildren: true);
                        //}
                        //else
                        //{
                        marketcenter = new MarketCenter(TopLevelMarketCenterIdsInOrder[i].Id, getChildren: true);
                        //marketcenter = new MarketCenter(marketcenterCategory.Id, getChildren: true, customType: type);
                        //}
                        //FORCE FEATURED

                        char firstLetter = marketcenter.Name.ToUpper()[0];

                        //create featured company list
                        if (marketcenter.isTopCompany) // && featuredMarketCenterList.Count <= 25
                        {
                            featuredMarketCenterList.Add(marketcenter);
                        }

                        //seperate market centers into alpha lists a-g h-p q-z
                        if (firstLetter >= '0' && firstLetter <= '9')      //&& alphaList1.Count <= 100
                        {
                            alphaList1.Add(marketcenter);                  //x++;
                        }
                        else if (firstLetter >= 'A' && firstLetter <= 'G') //&& alphaList1.Count <= 100
                        {
                            alphaList1.Add(marketcenter);                  // x++;
                        }
                        else if (firstLetter >= 'H' && firstLetter <= 'P') // && alphaList2.Count <= 25
                        {
                            alphaList2.Add(marketcenter);                  //y++;
                        }
                        else if (firstLetter >= 'Q' && firstLetter <= 'Z') // && alphaList3.Count <= 25
                        {
                            alphaList3.Add(marketcenter);                  //z++;
                        }

                        //TESTING SECTION --------------------limit number of market centers to load page faster
                        //if (featuredMarketCenterList.Count > 25 && alphaList1.Count > 25 && alphaList2.Count > 25 && alphaList3.Count > 25)
                        //{
                        //    break;
                        //}
                        //TESTING --------------------------------------------------------------------------
                    }
                }
                else
                {
                    //hacking

                    if (!string.IsNullOrEmpty(type))
                    {
                        int specAttrId       = 0;
                        int specAttrOptionId = 0;

                        specAttrList = specService.GetProductSpecificationAttributes(productId: 0);
                        foreach (var attr in specAttrList)
                        {
                            string typeOptionValue = "";
                            if (attr.SpecificationAttributeOption.SpecificationAttribute.Name == "Market Center Gateway Type")
                            {
                                specAttrId      = attr.SpecificationAttributeOption.SpecificationAttribute.Id;
                                typeOptionValue = attr.SpecificationAttributeOption.Name;
                                if (typeOptionValue == type)
                                {
                                    specAttrOptionId = attr.SpecificationAttributeOption.Id;
                                    break;
                                }
                            }
                        }

                        featuredMarketCenterList = GetTabData(true, type: type);
                        alphaList1 = GetTabData(null, '!', 'G', specAttrOptionId, type);
                        alphaList2 = GetTabData(null, 'H', 'P', specAttrOptionId, type);
                        alphaList3 = GetTabData(null, 'Q', 'Z', specAttrOptionId, type);
                    }
                    else
                    {
                        featuredMarketCenterList = GetTabData(true);
                        alphaList1 = GetTabData(null, '!', 'G');
                        alphaList2 = GetTabData(null, 'H', 'P');
                        alphaList3 = GetTabData(null, 'Q', 'Z');
                    }
                }

                //call build for featured list
                //top companies only (isFeatured)
                string isfeatured     = featuredMarketCenterList.Count > 0 ? BuildFeaturedCompanyHtml(featuredMarketCenterList, type) : "";
                string childLinksHtml = featuredMarketCenterList.Count > 0 ? BuildChildCompanyHtml(featuredMarketCenterList, type) : "";

                //call build html for each alpha list
                string alpha1       = alphaList1.Count > 0 ? BuildTabHtml(alphaList1, type) : "";
                string alpha2       = alphaList2.Count > 0 ? BuildTabHtml(alphaList2, type) : "";
                string alpha3       = alphaList3.Count > 0 ? BuildTabHtml(alphaList3, type) : "";
                string cantFindHtml = BuildCantFindHtml();

                //add featured and alphas to dictionary
                marketCenterTabsDict.Add("Featured Companies", isfeatured);
                marketCenterTabsDict.Add("Companies A - G", alpha1);
                marketCenterTabsDict.Add("Companies H - P", alpha2);
                marketCenterTabsDict.Add("Companies Q - Z", alpha3);
                marketCenterTabsDict.Add("Can't Find Your Company?", cantFindHtml);
                marketCenterTabsDict.Add("HiddenHtml", childLinksHtml);

                return(marketCenterTabsDict);
            }
            catch (Exception ex)
            {
                logger.Error("MarketCenter.cs GetMarketCenterHtml : ", ex);

                return(marketCenterTabsDict);
            }
        }