/// <summary> /// 将数据库中的信息转换成EditModel实体 /// </summary> /// <param name="blogThread">文章实体</param> /// <returns>编辑文章的EditModel</returns> public static BlogThreadEditModel AsEditModel(this BlogThread blogThread) { return(new BlogThreadEditModel { ThreadId = blogThread.ThreadId, Subject = blogThread.Subject, Body = blogThread.GetBody(), IsSticky = blogThread.IsSticky, IsLocked = blogThread.IsLocked, PrivacyStatus = blogThread.PrivacyStatus, Keywords = blogThread.Keywords, Summary = blogThread.Summary, IsDraft = blogThread.IsDraft, FeaturedImageAttachmentId = blogThread.FeaturedImageAttachmentId }); }
/// <summary> /// BlogThread转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="blogThread">日志实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(BlogThread blogThread) { Document doc = new Document(); //索引日志基本信息 doc.Add(new Field(BlogIndexDocument.ThreadId, blogThread.ThreadId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.TenantTypeId, blogThread.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.OwnerId, blogThread.OwnerId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.IsEssential, blogThread.IsEssential ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.Keywords, blogThread.Keywords ?? "", Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Summary, blogThread.Summary ?? "", Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.UserId, blogThread.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.Subject, blogThread.Subject.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Body, HtmlUtility.TrimHtml(blogThread.GetBody(), 0).ToLower(), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Author, blogThread.Author, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.DateCreated, DateTools.DateToString(blogThread.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.AuditStatus, ((int)blogThread.AuditStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.PrivacyStatus, ((int)blogThread.PrivacyStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //索引日志tag foreach (string tagName in blogThread.TagNames) { doc.Add(new Field(BlogIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } //索引日志用户分类名称 IEnumerable <string> ownerCategoryNames = blogThread.OwnerCategoryNames; if (ownerCategoryNames != null) { foreach (string ownerCategoryName in ownerCategoryNames) { doc.Add(new Field(BlogIndexDocument.OwnerCategoryName, ownerCategoryName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } } //索引日志站点分类ID long?siteCategoryId = blogThread.SiteCategoryId; if (siteCategoryId.HasValue) { doc.Add(new Field(BlogIndexDocument.SiteCategoryId, siteCategoryId.Value.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } return(doc); }
/// <summary> /// 撰写日志/转载日志 /// </summary> /// <param name="blogThread">日志实体</param> public bool Create(BlogThread blogThread, string privacyStatus1 = null, string privacyStatus2 = null) { //设计要点 //1、使用AuditService设置审核状态; //2、注意调用AttachmentService转换临时附件; //3、需要触发的事件参见《设计说明书-日志》 //4、草稿的审核状态为待审核; //5、转载的日志还需要为原日志转载数+1(调用计数服务); EventBus <BlogThread> .Instance().OnBefore(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态,草稿的审核状态为待审核 if (blogThread.IsDraft) { blogThread.AuditStatus = AuditStatus.Pending; } else { AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForCreate(blogThread.UserId, blogThread); } long threadId = 0; long.TryParse(blogThreadRepository.Insert(blogThread).ToString(), out threadId); if (threadId > 0) { //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); attachmentService.ToggleTemporaryAttachments(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); //原日志转载数+1 if (blogThread.IsReproduced) { CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().ReproduceCount(), blogThread.OriginalThreadId, blogThread.OwnerId, 1, true); } //用户内容计数+1 if (!blogThread.IsDraft) { OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(blogThread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); atUserService.ResolveBodyForEdit(blogThread.GetBody(), blogThread.UserId, blogThread.ThreadId); //设置隐私状态 UpdatePrivacySettings(blogThread, privacyStatus1, privacyStatus2); EventBus <BlogThread> .Instance().OnAfter(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BlogThread, AuditEventArgs> .Instance().OnAfter(blogThread, new AuditEventArgs(null, blogThread.AuditStatus)); return(true); } return(false); }