/// <summary> /// body是否有显示的权限(主要是针对于回复可见的情况) /// </summary> /// <param name="authorizer"></param> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_BodyShow(this Authorizer authorizer, long threadId) { BarThreadService service = new BarThreadService(); BarPostService barPostService = new Bar.BarPostService(); BarThread thread = service.Get(threadId); if (thread == null) { return(false); } if (!thread.IsHidden) { return(true); } if (barPostService.IsPosted(UserContext.CurrentUser == null ? 0 : UserContext.CurrentUser.UserId, threadId)) { return(true); } return(BarThread_Edit(authorizer, thread)); }
/// <summary> /// 动态处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarPostActivityModule_After(BarPost sender, AuditEventArgs eventArgs) { ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //生成动态 { BarThreadService barThreadService = new BarThreadService(); BarThread barThread = barThreadService.Get(sender.ThreadId); if (barThread == null) return; if (sender.UserId == barThread.UserId) return; var barUrlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); if (barUrlGetter == null) return; if (sender.ParentId > 0) { BarPost parentPost = new BarPostService().Get(sender.ParentId); if (parentPost == null) return; if (parentPost.UserId == sender.UserId) return; } Activity actvity = Activity.New(); actvity.ActivityItemKey = ActivityItemKeys.Instance().CreateBarPost(); actvity.ApplicationId = BarConfig.Instance().ApplicationId; //仅一级回复可以上传附件 if (sender.ParentId == 0) { AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BarPost()); IEnumerable<Attachment> attachments = attachmentService.GetsByAssociateId(sender.PostId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) actvity.HasImage = true; //actvity.HasMusic = barThread.HasMusic; //actvity.HasVideo = barThread.HasVideo; } actvity.IsOriginalThread = true; actvity.IsPrivate = barUrlGetter.IsPrivate(barThread.SectionId); actvity.OwnerId = barThread.SectionId; actvity.OwnerName = barThread.BarSection.Name; actvity.OwnerType = barUrlGetter.ActivityOwnerType; actvity.ReferenceId = barThread.ThreadId; actvity.ReferenceTenantTypeId = TenantTypeIds.Instance().BarThread(); actvity.SourceId = sender.PostId; actvity.TenantTypeId = TenantTypeIds.Instance().BarPost(); actvity.UserId = sender.UserId; //创建从属内容,不向自己的动态收件箱推送动态 activityService.Generate(actvity, false); } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().BarPost(), sender.PostId); } }
/// <summary> /// 是否具有编辑帖子的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="threadId">帖子的id</param> /// <returns>是否具有对应的权限</returns> public static bool BarThread_Edit(this Authorizer authorizer, long threadId) { BarThreadService service = new BarThreadService(); BarThread thread = service.Get(threadId); if (thread == null) { return(false); } return(BarThread_Edit(authorizer, thread)); }
/// <summary> /// 将ViewModel转换成数据库存储实体 /// </summary> /// <returns></returns> public BarThread AsBarThread() { BarThreadService barThreadService = new BarThreadService(); BarSectionService barSectionService = new BarSectionService(); BarThread barThread = null; if (this.ThreadId > 0) { barThread = barThreadService.Get(this.ThreadId); } else { barThread = BarThread.New(); barThread.UserId = UserContext.CurrentUser.UserId; barThread.Author = UserContext.CurrentUser.DisplayName; } if (barThread == null) { return(barThread); } barThread.SectionId = this.SectionId; if (this.StickyDate.CompareTo(DateTime.UtcNow) > 0) { barThread.StickyDate = this.StickyDate; } barThread.Subject = this.Subject; barThread.Body = this.Body; barThread.IsHidden = this.IsHidden; barThread.IsEssential = this.IsEssential; barThread.IsSticky = this.IsSticky; barThread.LastModified = DateTime.UtcNow; barThread.TenantTypeId = TenantTypeIds.Instance().Bar(); BarSection barSection = barSectionService.Get(this.SectionId); if (barSection != null) { barThread.OwnerId = barSection.OwnerId; barThread.TenantTypeId = barSection.TenantTypeId; } return(barThread); }
/// <summary> /// 创建评分 /// </summary> /// <param name="rating">评分</param> /// <returns>true-评分成功,false-评分失败(可能今日评分已超过限额)</returns> public bool Create(BarRating rating) { BarThreadService barThreadService = new BarThreadService(); BarThread thread = barThreadService.Get(rating.ThreadId); EventBus<BarRating>.Instance().OnBefore(rating, new CommonEventArgs(EventOperationType.Instance().Create())); bool result = false; bool.TryParse(barRatingRepository.Insert(rating).ToString(), out result); if (result) { //给楼主加威望/交易积分 IUserService userService = DIContainer.Resolve<IUserService>(); userService.ChangePoints(thread.UserId, 0, rating.ReputationPoints, rating.TradePoints); PointService pointService = new PointService(); pointService.CreateRecord(thread.UserId, "帖子评分", "发布的帖子被其他用户评分", 0, rating.ReputationPoints, rating.TradePoints); EventBus<BarRating>.Instance().OnAfter(rating, new CommonEventArgs(EventOperationType.Instance().Create())); } return result; }
void BarRatingEventModule_After(BarRating sender, CommonEventArgs eventArgs) { ActivityService activityService = new ActivityService(); if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { Activity actvity = Activity.New(); actvity.ActivityItemKey = ActivityItemKeys.Instance().CreateBarRating(); actvity.ApplicationId = BarConfig.Instance().ApplicationId; BarThreadService barThreadService = new BarThreadService(); BarThread barThread = barThreadService.Get(sender.ThreadId); if (barThread == null) return; var barUrlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); if (barUrlGetter == null) return; actvity.IsOriginalThread = true; actvity.IsPrivate = barUrlGetter.IsPrivate(barThread.SectionId); actvity.OwnerId = barThread.SectionId; actvity.OwnerName = barThread.BarSection.Name; actvity.OwnerType = barUrlGetter.ActivityOwnerType; actvity.ReferenceId = barThread.ThreadId; actvity.ReferenceTenantTypeId = TenantTypeIds.Instance().BarThread(); actvity.SourceId = sender.RatingId; actvity.TenantTypeId = TenantTypeIds.Instance().BarRating(); actvity.UserId = sender.UserId; //自己回复自己时,不向自己的动态收件箱推送动态 if (actvity.UserId == barThread.UserId) activityService.Generate(actvity, false); else activityService.Generate(actvity, true); } else { activityService.DeleteSource(TenantTypeIds.Instance().BarRating(), sender.RatingId); } }
/// <summary> /// 创建评分 /// </summary> /// <param name="rating">评分</param> /// <returns>true-评分成功,false-评分失败(可能今日评分已超过限额)</returns> public bool Create(BarRating rating) { BarThreadService barThreadService = new BarThreadService(); BarThread thread = barThreadService.Get(rating.ThreadId); EventBus <BarRating> .Instance().OnBefore(rating, new CommonEventArgs(EventOperationType.Instance().Create())); bool result = false; bool.TryParse(barRatingRepository.Insert(rating).ToString(), out result); if (result) { //给楼主加威望/交易积分 IUserService userService = DIContainer.Resolve <IUserService>(); userService.ChangePoints(thread.UserId, 0, rating.ReputationPoints, rating.TradePoints); PointService pointService = new PointService(); pointService.CreateRecord(thread.UserId, "帖子评分", "发布的帖子被其他用户评分", 0, rating.ReputationPoints, rating.TradePoints); EventBus <BarRating> .Instance().OnAfter(rating, new CommonEventArgs(EventOperationType.Instance().Create())); } return(result); }
/// <summary> /// 是否具有编辑帖子的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="threadId">帖子的id</param> /// <returns>是否具有对应的权限</returns> public static bool BarThread_Edit(this Authorizer authorizer, long threadId) { BarThreadService service = new BarThreadService(); BarThread thread = service.Get(threadId); if (thread == null) return false; return BarThread_Edit(authorizer, thread); }
/// <summary> /// body是否有显示的权限(主要是针对于回复可见的情况) /// </summary> /// <param name="authorizer"></param> /// <param name="threadId"></param> /// <returns></returns> public static bool BarThread_BodyShow(this Authorizer authorizer, long threadId) { BarThreadService service = new BarThreadService(); BarPostService barPostService = new Bar.BarPostService(); BarThread thread = service.Get(threadId); if (thread == null) return false; if (!thread.IsHidden) return true; if (barPostService.IsPosted(UserContext.CurrentUser == null ? 0 : UserContext.CurrentUser.UserId, threadId)) return true; //todo:需要判断是否已经留言过 return BarThread_Edit(authorizer, thread); }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarPostNoticeModule_After(BarPost sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //创建回帖发通知 { BarThreadService barThreadService = new BarThreadService(); BarThread barThread = barThreadService.Get(sender.ThreadId); if (barThread == null) return; long toUserId = barThread.UserId; //自己给自己的帖子进行回帖,不必通知 if (sender.UserId == barThread.UserId) return; if (sender.ParentId > 0) { BarPostService barPostService = new BarPostService(); BarPost parentPost = barPostService.Get(sender.ParentId); if (parentPost == null || (parentPost.UserId == sender.UserId)) return; toUserId = parentPost.UserId; } NoticeService noticeService = Tunynet.DIContainer.Resolve<NoticeService>(); Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.PostId; notice.RelativeObjectName = HtmlUtility.TrimHtml(barThread.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetailGotoPost(sender.PostId)); notice.TemplateName = NoticeTemplateNames.Instance().NewReply(); noticeService.Create(notice); } }
/// <summary> /// 将ViewModel转换成数据库存储实体 /// </summary> /// <returns></returns> public BarThread AsBarThread() { BarThreadService barThreadService = new BarThreadService(); BarSectionService barSectionService = new BarSectionService(); BarThread barThread = null; if (this.ThreadId > 0) { barThread = barThreadService.Get(this.ThreadId); } else { barThread = BarThread.New(); barThread.UserId = UserContext.CurrentUser.UserId; barThread.Author = UserContext.CurrentUser.DisplayName; } if (barThread == null) return barThread; barThread.SectionId = this.SectionId; if (this.StickyDate.CompareTo(DateTime.UtcNow) > 0) barThread.StickyDate = this.StickyDate; barThread.Subject = this.Subject; barThread.Body = this.Body; barThread.IsHidden = this.IsHidden; barThread.IsEssential = this.IsEssential; barThread.IsSticky = this.IsSticky; barThread.LastModified = DateTime.UtcNow; barThread.TenantTypeId = TenantTypeIds.Instance().Bar(); BarSection barSection = barSectionService.Get(this.SectionId); if (barSection != null) { barThread.OwnerId = barSection.OwnerId; barThread.TenantTypeId = barSection.TenantTypeId; } return barThread; }