/// <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); }
//todo:zhengw:未处理VersionNum,感觉没用 /// <summary> /// 创建词条版本 /// </summary> /// <param name="wikiPageVersion">词条实体</param> public void CreatePageVersion(WikiPageVersion wikiPageVersion, bool Is) { WikiPage wikiPage = Get(wikiPageVersion.PageId); if (wikiPage == null) { return; } EventBus <WikiPageVersion> .Instance().OnBefore(wikiPageVersion, new CommonEventArgs(EventOperationType.Instance().Create())); AuditService auditService = new AuditService(); //auditService.ChangeAuditStatusForCreate(wikiPageVersion.UserId, wikiPageVersion); wikiPageVersionRepository.Insert(wikiPageVersion); if (wikiPageVersion.VersionId > 0) { wikiPage.EditionCount++; wikiPage.LastModified = DateTime.UtcNow; wikiPageRepository.Update(wikiPage); //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().WikiPage()); attachmentService.ToggleTemporaryAttachments(wikiPage.OwnerId, TenantTypeIds.Instance().WikiPage(), wikiPageVersion.PageId); EventBus <WikiPageVersion> .Instance().OnAfter(wikiPageVersion, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <WikiPageVersion, AuditEventArgs> .Instance().OnAfter(wikiPageVersion, new AuditEventArgs(null, wikiPageVersion.AuditStatus)); } }
/// <summary> /// 删除词条版本 /// </summary> /// <param name="wikiPageVersion">词条版本</param> public void DeletePageVersion(WikiPageVersion wikiPageVersion) { if (wikiPageVersion == null) { return; } WikiPage wikiPage = Get(wikiPageVersion.PageId); if (wikiPage == null) { return; } EventBus <WikiPageVersion> .Instance().OnBefore(wikiPageVersion, new CommonEventArgs(EventOperationType.Instance().Delete())); wikiPageVersionRepository.Delete(wikiPageVersion); if (wikiPage.EditionCount > 0) { wikiPage.EditionCount--; wikiPageRepository.Update(wikiPage); } EventBus <WikiPageVersion> .Instance().OnAfter(wikiPageVersion, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <WikiPageVersion, AuditEventArgs> .Instance().OnAfter(wikiPageVersion, new AuditEventArgs(wikiPageVersion.AuditStatus, null)); }
/// <summary> /// 删除词条版本 /// </summary> /// <param name="versionId">词条版本Id</param> public void DeletePageVersion(long versionId) { WikiPageVersion wikiPageVersion = wikiPageVersionRepository.Get(versionId); if (wikiPageVersion == null) { return; } DeletePageVersion(wikiPageVersion); }
/// <summary> /// 新建实体时使用 /// </summary> public static WikiPageVersion New() { WikiPageVersion wikiPageVersion = new WikiPageVersion() { Title = string.Empty, Author = string.Empty, Summary = string.Empty, TenantTypeId = TenantTypeIds.Instance().Wiki(), Reason = string.Empty, DateCreated = DateTime.UtcNow, IP = WebUtility.GetIP() }; return(wikiPageVersion); }
/// <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); }
/// <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); }
/// <summary> /// 批准/不批准词条版本 /// </summary> /// <param name="versionId">待被更新的词条版本Id</param> /// <param name="isApproved">是否通过审核</param> public void ApprovePageVersion(long versionId, bool isApproved) { WikiPageVersion wikiPageVersion = wikiPageVersionRepository.Get(versionId); AuditStatus newAuditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail; if (wikiPageVersion.AuditStatus == newAuditStatus) { return; } AuditStatus oldAuditStatus = wikiPageVersion.AuditStatus; wikiPageVersion.AuditStatus = newAuditStatus; wikiPageVersionRepository.Update(wikiPageVersion); string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved(); EventBus <WikiPageVersion> .Instance().OnAfter(wikiPageVersion, new CommonEventArgs(operationType)); EventBus <WikiPageVersion, AuditEventArgs> .Instance().OnAfter(wikiPageVersion, new AuditEventArgs(oldAuditStatus, newAuditStatus)); }