コード例 #1
0
        /// <summary>
        /// 更新链接
        /// </summary>
        public void Edit_GET()
        {
            object data;
            int    linkId     = int.Parse(base.Request.QueryString["linkId"]);
            int    bindId     = 0;
            int    categoryId = 0;
            string plinks     = "";

            SiteLinkDto link = ServiceCall.Instance.SiteService.GetLinkById(this.SiteId, linkId);

            string bindTitle = String.Empty;

            string[] binds = (link.Bind ?? "").Split(':');
            if (binds.Length != 2 || binds[1] == String.Empty)
            {
                binds = null;
            }
            else
            {
                bindId = int.Parse(binds[1]);

                if (binds[0] == "category")
                {
                    CategoryDto cate = ServiceCall.Instance.SiteService.GetCategory(this.SiteId, bindId);

                    bindTitle = cate.Id > 0 ?
                                String.Format("栏目:{0}", cate.Name) :
                                null;
                    categoryId = cate.Id;
                }
                else if (binds[0] == "archive")
                {
                    ArchiveDto archive = ServiceCall.Instance.ArchiveService
                                         .GetArchiveById(this.SiteId, bindId);

                    if (archive.Id <= 0)
                    {
                        binds = null;
                    }
                    else
                    {
                        bindTitle = String.Format("文档:{0}", archive.Title);
                    }
                }
            }

            string linkTypeName,
                   resouce;

            switch ((SiteLinkType)link.Type)
            {
            case SiteLinkType.FriendLink: linkTypeName = "友情链接";
                resouce = ResourceMap.GetPageContent(ManagementPage.Link_SiteLinkEdit);
                break;

            default:
            case SiteLinkType.CustomLink: linkTypeName = "自定义链接";
                resouce = ResourceMap.GetPageContent(ManagementPage.Link_SiteLinkEdit);
                break;

            case SiteLinkType.Navigation: linkTypeName = "网站导航";
                resouce = ResourceMap.GetPageContent(ManagementPage.Link_SiteLinkEdit_Navigator);
                break;
            }

            //plinks
            StringBuilder             sb          = new StringBuilder();
            IEnumerable <SiteLinkDto> parentLinks = ServiceCall.Instance.SiteService
                                                    .GetLinksByType(this.SiteId, link.Type, true);

            foreach (SiteLinkDto _link in parentLinks)
            {
                if (_link.Pid == 0)
                {
                    sb.Append("<option value=\"").Append(_link.Id.ToString())
                    .Append("\">").Append(_link.Text).Append("</option>");
                }
            }
            plinks = sb.ToString();

            string json = JsonSerializer.Serialize(
                new
            {
                Id         = link.Id,
                Text       = link.Text,
                Uri        = link.Uri,
                OrderIndex = link.OrderIndex,
                Btn        = "保存",
                BindId     = bindId,
                BindType   = binds == null ? "" : binds[0],
                BindTitle  = bindTitle == String.Empty ? "未绑定" : bindTitle,
                Target     = link.Target,
                Type       = (int)link.Type,
                ImgUrl     = link.ImgUrl,
                Visible    = link.Visible.ToString(),
                Pid        = link.Pid,
                CategoryId = categoryId
            });

            base.RenderTemplate(resouce, new
            {
                entity        = json,
                LinkType      = (int)link.Type,
                linkTypeName  = linkTypeName,
                categoryNodes = this.GetCategorySelector(this.SiteId, -1),
                plinks        = plinks
            });
        }