Esempio n. 1
0
        /// <summary>
        /// 回滚版本
        /// </summary>
        /// <param name="versionId">回滚到的版本</param>
        public void RollbackPageVersion(long versionId, int versionNum)
        {
            WikiPageVersion wikiPageVersion = GetPageVersion(versionId);

            if (wikiPageVersion == null)
            {
                return;
            }
            WikiPage wikiPage = Get(wikiPageVersion.PageId);

            if (wikiPage == null)
            {
                return;
            }
            WikiPageVersion newWikiPageVersion = WikiPageVersion.New();

            newWikiPageVersion.PageId       = wikiPageVersion.PageId;
            newWikiPageVersion.TenantTypeId = wikiPageVersion.TenantTypeId;
            newWikiPageVersion.OwnerId      = wikiPageVersion.OwnerId;
            //todo:zhengw:未处理VersionNum,感觉没用
            newWikiPageVersion.VersionNum  = 0;
            newWikiPageVersion.Title       = wikiPageVersion.Title;
            newWikiPageVersion.UserId      = wikiPageVersion.UserId;
            newWikiPageVersion.Author      = wikiPageVersion.Author;
            newWikiPageVersion.Summary     = Tunynet.Utilities.HtmlUtility.TrimHtml(wikiPageVersion.GetBody(), 200);
            newWikiPageVersion.Body        = wikiPageVersion.GetBody();
            newWikiPageVersion.AuditStatus = AuditStatus.Success;
            string versionNumUrl = string.Format("<a  target='_blank' href={0}>版本{1}</a>", SiteUrls.Instance().PageDetail(wikiPageVersion.PageId, versionId), versionNum);

            newWikiPageVersion.Reason = string.Format("回滚到{0}", versionNumUrl);
            wikiPageVersionRepository.Insert(newWikiPageVersion);
        }
Esempio n. 2
0
        /// <summary>
        /// 撰写词条
        /// </summary>
        /// <param name="wikiPage">词条实体</param>
        public bool Create(WikiPage wikiPage, string body)
        {
            EventBus <WikiPage> .Instance().OnBefore(wikiPage, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态,草稿的审核状态为待审核
            AuditService auditService = new AuditService();

            auditService.ChangeAuditStatusForCreate(wikiPage.UserId, wikiPage);

            long pageId = 0;

            long.TryParse(wikiPageRepository.Insert(wikiPage).ToString(), out pageId);

            if (pageId > 0)
            {
                WikiPageVersion wikiPageVersion = WikiPageVersion.New();
                wikiPageVersion.PageId       = pageId;
                wikiPageVersion.TenantTypeId = wikiPage.TenantTypeId;
                wikiPageVersion.OwnerId      = wikiPage.OwnerId;
                wikiPageVersion.VersionNum   = 1;
                wikiPageVersion.Title        = wikiPage.Title;
                wikiPageVersion.UserId       = wikiPage.UserId;
                wikiPageVersion.Author       = wikiPage.Author;
                wikiPageVersion.Summary      = StringUtility.Trim(Tunynet.Utilities.HtmlUtility.StripHtml(body, true, false).Replace("\r", "").Replace("\n", ""), 200);
                wikiPageVersion.Body         = body;
                wikiPageVersion.AuditStatus  = AuditStatus.Success;
                wikiPageVersionRepository.Insert(wikiPageVersion);
                //转换临时附件
                AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().WikiPage());
                attachmentService.ToggleTemporaryAttachments(wikiPage.OwnerId, TenantTypeIds.Instance().WikiPage(), wikiPageVersion.PageId);

                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(wikiPage.UserId, OwnerDataKeys.Instance().PageCount(), 1);

                EventBus <WikiPage> .Instance().OnAfter(wikiPage, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <WikiPage, AuditEventArgs> .Instance().OnAfter(wikiPage, new AuditEventArgs(null, wikiPage.AuditStatus));

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// 转换成WikiPageVersion
        /// </summary>
        public WikiPageVersion AsWikiPageVersion()
        {
            WikiPageVersion pageVersion = WikiPageVersion.New();

            if (this.PageId > 0)
            {
                WikiService service = new WikiService();
                WikiPage    page    = service.Get(this.PageId);
                if (page != null)
                {
                    pageVersion.Title = page.Title;
                }
            }
            else
            {
                pageVersion.Title = this.Title;
            }

            if (this.OwnerId.HasValue)
            {
                pageVersion.OwnerId = this.OwnerId.Value;
            }
            else
            {
                pageVersion.OwnerId = UserContext.CurrentUser.UserId;
            }

            pageVersion.UserId = UserContext.CurrentUser.UserId;
            pageVersion.Author = UserContext.CurrentUser.DisplayName;
            pageVersion.PageId = this.PageId;

            if (!string.IsNullOrEmpty(this.Summary))
            {
                pageVersion.Summary = this.Summary;
            }
            pageVersion.Body = this.Body;
            if (!string.IsNullOrEmpty(this.Reason))
            {
                pageVersion.Reason = this.Reason;
            }

            return(pageVersion);
        }