/// <summary> /// 更新回复贴 /// </summary> /// <param name="post">回复贴</param> public void Update(BarPost post, long userId) { EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Update())); auditService.ChangeAuditStatusForUpdate(userId, post); barPostRepository.Update(post); new AtUserService(TenantTypeIds.Instance().BarPost()).ResolveBodyForEdit(post.GetBody(), post.UserId, post.PostId); EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Update())); }
/// <summary> /// 数据库中的对象转换为EditModel /// </summary> /// <returns></returns> public static BarPostEditModel AsEditModel(this BarPost post) { BarSettings barSettings = DIContainer.Resolve <ISettingsManager <BarSettings> >().Get(); BarThread thread = new BarThreadService().Get(post.ThreadId); return(new BarPostEditModel { Body = post.GetBody(), ParentId = post.ParentId, PostId = post.PostId, Subject = thread.Subject, ThreadId = post.ThreadId, SectionId = post.SectionId }); }
/// <summary> /// 创建回复贴 /// </summary> /// <param name="post">回复贴</param> public bool Create(BarPost post) { BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(post.SectionId); if (barSection == null) { return(false); } EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(post.UserId, post); long id = 0; long.TryParse(barPostRepository.Insert(post).ToString(), out id); if (id > 0) { new AttachmentService(TenantTypeIds.Instance().BarPost()).ToggleTemporaryAttachments(post.UserId, TenantTypeIds.Instance().BarPost(), id); //计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true); if (post.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数+1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(post.SectionId, OwnerDataKeys.Instance().PostCount(), 1); } else if (post.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(post.UserId, OwnerDataKeys.Instance().PostCount(), 1); } //更新帖子主题计数缓存 RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(BarThread)).RealTimeCacheHelper; string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(post.ThreadId); ICacheService cacheService = DIContainer.Resolve <ICacheService>(); BarThread barThread = cacheService.Get <BarThread>(cacheKey); if (barThread != null && barThread.ThreadId > 0) { barThread.PostCount++; cacheService.Set(cacheKey, barThread, CachingExpirationType.SingleObject); } new AtUserService(TenantTypeIds.Instance().BarPost()).ResolveBodyForEdit(post.GetBody(), post.UserId, post.PostId); EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(null, post.AuditStatus)); } return(id > 0); }