コード例 #1
0
        /// <summary>
        /// 添加插件到页面,保存时
        /// </summary>
        /// <param name="webpartId">部件id,唯一部件</param>
        /// <param name="pageId">00000000-0000-0000-0000-000000000000  Guid.NewGuid().ToString()</param>
        /// <param name="part">部件显示区域</param>
        /// <param name="webpartname"></param>
        public Dictionary <string, string> AddWebPartToPage(string webpartId, string pageId, string part, string webpartname)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            OThinker.H3.Site.SitePage page = this.Engine.SiteManager.GetPage(pageId);
            if (page == null || page == default(OThinker.H3.Site.SitePage))
            {
                result.Add("Error", "页面不存在");
                return(result);
            }

            SiteWebPartInstance inst = new SiteWebPartInstance();
            int recordCount          = 0;
            int pageCount            = 0;

            SiteWebPartInstance[] webparts = this.Engine.SiteManager.GetAllWebPartInsts();
            if (webparts != null && webparts.Length > 0)
            {
                int i = 0;
                foreach (SiteWebPartInstance webpart in webparts)
                {
                    if (webpart.PagePart == part && webpart.PageId == pageId)
                    {
                        i++;
                    }
                }
                recordCount = i;
                pageCount   = recordCount % 1 > 0 ? recordCount / 1 + 1 : recordCount / 1;
            }
            inst.CreatedTime = DateTime.Now;
            inst.CreatedBy   = UserValidatorFactory.CurrentUser.UserID;
            inst.PageId      = pageId;
            inst.PagePart    = part;
            inst.SortKey     = recordCount + 1;
            inst.WebPartId   = webpartId;

            List <SiteWebPartInstanceValue> source = new List <SiteWebPartInstanceValue>();

            OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue();
            obj.AttributeName  = "Title";
            obj.AttributeType  = AttributeType.PublicAttribute;
            obj.AttributeValue = webpartname;
            obj.InstanceId     = webpartId;
            obj.ParentIndex    = 1;

            source.Add(obj);
            inst.Attributes = source.ToArray();
            this.Engine.SiteManager.AddWebPartInst(inst);
            result.Add("Success", inst.ObjectID);
            this.InstId = inst.ObjectID;
            return(result);
        }
        /// <summary>
        /// 保存页面
        /// </summary>
        /// <param name="PageId"></param>
        /// <param name="PageTitle"></param>
        /// <param name="TempId"></param>
        /// <param name="OrgId"></param>
        /// <returns></returns>
        public JsonResult SavePage(string PageId, string PageTitle, string TempId, string OrgId)
        {
            return(this.ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(true);

                bool IsNewPage = string.IsNullOrEmpty(PageId);
                if (string.IsNullOrEmpty(PageTitle) || string.IsNullOrEmpty(TempId) || string.IsNullOrEmpty(OrgId))
                {
                    result.Success = false;
                    result.Message = "缺少参数[模板id, 页面标题, 组织结构id]";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                OThinker.H3.Site.SitePage SitePage;
                if (IsNewPage)
                {
                    SitePage = new OThinker.H3.Site.SitePage();
                    SitePage.CreatedTime = DateTime.Now;
                    SitePage.CreatedBy = UserValidatorFactory.CurrentUser.UserID;
                }
                else
                {
                    SitePage = this.Engine.SiteManager.GetPage(PageId);
                    if (SitePage == null)
                    {
                        result.Success = false;
                        result.Message = "模板id无效";
                        return Json(result, JsonRequestBehavior.AllowGet);
                    }
                    SitePage.LastModifiedTime = DateTime.Now;
                    SitePage.LastModifiedBy = UserValidatorFactory.CurrentUser.UserID;
                }

                //TODO:是否有必要做保存校验

                SitePage.TemplateId = TempId;
                SitePage.Title = PageTitle;
                SitePage.OrgId = OrgId;
                if ((IsNewPage && !this.Engine.SiteManager.AddPage(SitePage)) ||
                    (!IsNewPage && !this.Engine.SiteManager.UpdatePage(SitePage)))
                {
                    result.Success = false;
                    result.Message = "保存失败";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                result.Message = "保存成功";
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 删除页面
        /// </summary>
        /// <param name="PageId"></param>
        /// <returns></returns>
        public JsonResult RemoveManagedPage(string PageId)
        {
            return(this.ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(true);

                if (string.IsNullOrEmpty(PageId))
                {
                    result.Success = false;
                    result.Message = "无效的参数";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                Guid testGuid;
                if (!Guid.TryParse(PageId, out testGuid))
                {
                    result.Success = false;
                    result.Message = "无效的参数";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                if (testGuid == Guid.Empty)
                {
                    result.Success = false;
                    result.Message = "主页不允许删除";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                OThinker.H3.Site.SitePage obj = this.Engine.SiteManager.GetPage(PageId);
                if (obj == null || obj == default(OThinker.H3.Site.SitePage))
                {
                    result.Success = false;
                    result.Message = "不存在的页面";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                var userValidator = UserValidatorFactory.CurrentUser;
                if (userValidator != null && (userValidator.ValidateAdministrator() || userValidator.ValidateOrgAdmin(obj.OrgId)))
                {
                    this.Engine.SiteManager.DeletePage(obj);
                    result.Message = "删除成功";
                }
                else
                {
                    result.Success = false;
                    result.Message = "没有权限";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 获取页面参数
        /// </summary>
        /// <param name="PageId"></param>
        /// <returns></returns>
        public JsonResult LoadPage(string PageId)
        {
            return(this.ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(true);
                //加载模板
                List <Template> Templates = new List <Template>();
                SitePage Page = new SitePage();

                OThinker.H3.Site.SitePageTemplate[] templates = this.Engine.SiteManager.GetAllPageTemplates();
                foreach (OThinker.H3.Site.SitePageTemplate template in templates)
                {
                    Templates.Add(new Template
                    {
                        TemplateName = template.TemplateName,
                        TemplateId = template.ObjectID
                    });
                }

                OThinker.H3.Site.SitePage SitePage = this.Engine.SiteManager.GetPage(PageId);
                if (SitePage != null)
                {
                    Page.PageId = PageId;
                    Page.PageTitle = SitePage.Title;
                    Page.TempId = SitePage.TemplateId;
                    Page.OrgId = SitePage.OrgId;
                }
                else
                {
                    Page = null;
                }
                var Extend = new
                {
                    Page = Page,
                    Templates = Templates,
                };
                result.Extend = Extend;
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }