Ejemplo n.º 1
0
        private static string BuildListForHtml(IEnumerable <CategoryInfo> list, int parentId = 0, int selectId = 0, WebLanguage language = WebLanguage.zh_cn)
        {
            var pList = list.Where(nc => nc.ParentId == parentId);

            if (pList.Count() == 0)
            {
                return(string.Empty);
            }
            var sb = new StringBuilder();

            sb.AppendFormat("{0}", parentId != 0 ? "<ul>" : string.Empty);
            foreach (var item in pList)
            {
                if (item.IsEnabled && !item.IsDeleted)
                {
                    sb.AppendFormat("<li{0}>", item.Id == selectId ? " class=\"current\"" : string.Empty);

                    //创建链接 Start
                    sb.Append(CategoryLinkUrlHelper.BuildLink(item, string.Empty, null, language));
                    //创建链接 End

                    //递归
                    sb.Append(BuildListForHtml(list, item.Id, selectId, language));
                    sb.AppendLine("</li>");
                }
            }
            sb.AppendFormat("{0}", parentId != 0 ? "</ul>" : string.Empty);
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public ActionResult SubCategoryListForChannelPage(int rootId, int selectedId, WebLanguage language = WebLanguage.zh_cn)
        {
            if (rootId == 0)
            {
                //在当前页面不会列出此站点的所有类别的
                return(Content(string.Empty));
            }
            StringBuilder sbHtml = new StringBuilder();
            Func <IEnumerable <CategoryInfo>, StringBuilder> fb = null;

            fb = (n1) =>
            {
                StringBuilder sb = new StringBuilder();
                foreach (var item in n1)
                {
                    sb.AppendFormat("<h3{1}>{0}</h3>", CategoryLinkUrlHelper.BuildLink(item, language), item.Id == selectedId ? " class=\"current\"" : string.Empty);
                    var subList = CategoryService.ListByParentId(item.Id, true);
                    if (subList.Count() > 0)
                    {
                        sb.Append("<ul>");
                        foreach (var subItem in subList)
                        {
                            sb.AppendFormat("<li{1}>{0}</li>", CategoryLinkUrlHelper.BuildLink(subItem, language), subItem.Id == selectedId ? " class=\"current\"" : string.Empty);
                        }
                        sb.Append("</ul>");
                    }
                }
                return(sb);
            };
            var list = CategoryService.ListByParentId(rootId, true);

            sbHtml = fb(list);
            return(Content(sbHtml.ToString()));
        }
Ejemplo n.º 3
0
        public ActionResult CategoryListForHeader(int siteId)
        {
            string html     = string.Empty;
            var    siteInfo = SiteService.Get(siteId, true);

            if (siteInfo.Language == WebLanguage.en)
            {
                //英文的只显示二级分类
                var sb       = new StringBuilder();
                var pList    = CategoryService.ListBySiteId(siteId, true);
                var rootList = pList.Where(p => (p.ParentId == 0 && p.IsEnabled && !p.IsDeleted));
                foreach (var item in rootList)
                {
                    sb.Append("<li>");

                    //创建链接 Start
                    sb.Append(CategoryLinkUrlHelper.BuildLink(item, string.Empty, null, WebLanguage.en));
                    //创建链接 End

                    var subList = pList.Where(p => (p.ParentId == item.Id && p.IsEnabled && !p.IsDeleted));
                    if (subList.Count() > 0)
                    {
                        sb.Append("<ul>");
                        foreach (var sub in subList)
                        {
                            sb.Append("<li>");
                            //创建链接 Start
                            sb.Append(CategoryLinkUrlHelper.BuildLink(sub, string.Empty, null, WebLanguage.en));
                            //创建链接 End
                            sb.Append("</li>");
                        }
                        sb.Append("</ul>");
                    }
                    sb.Append("</li>");
                }
                html = sb.ToString();
            }
            else
            {
                html = CategoryService.RenderTreeViewForHtml(siteId);
            }
            return(Content(html));
        }
Ejemplo n.º 4
0
        public ActionResult RenderSubNavForChannelPage(int siteId, int catId, string customTitle, WebLanguage language = WebLanguage.zh_cn)
        {
            StringBuilder sbNav = new StringBuilder(string.Format("<a href=\"/{1}\">{0}</a>",
                                                                  LanguageResourceHelper.GetString("channel-sub-nav-home-text", language),
                                                                  (language == WebLanguage.zh_cn ? string.Empty : language.ToString())
                                                                  ));

            if (catId > 0)
            {
                var upList = CategoryService.ListUpById(siteId, catId);

                foreach (var item in upList)
                {
                    sbNav.AppendFormat("&nbsp;&nbsp;>&nbsp;&nbsp;{0}", CategoryLinkUrlHelper.BuildLink(item, language));
                }
            }
            if (!string.IsNullOrEmpty(customTitle))
            {
                sbNav.AppendFormat("&nbsp;&nbsp;>&nbsp;&nbsp;{0}", customTitle);
            }

            return(Content(sbNav.ToString()));
        }