Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            string url = string.Empty;
            long anchorPostId = context.Request.QueryString.Get<long>("anchorPostId");

            BarPostService barPostService = new BarPostService();
            BarPost post = barPostService.Get(anchorPostId);
            if (post == null)
                WebUtility.Return404(context);

            IBarUrlGetter urlGetter = BarUrlGetterFactory.Get(post.TenantTypeId);

            if (post != null)
            {
                int? childPostIndex = 0;
                if (post.ParentId != 0)
                {
                    childPostIndex = barPostService.GetPageIndexForChildrenPost(post.ParentId, post.PostId);
                }

                int pageIndex = barPostService.GetPageIndexForPostInThread(post.ThreadId, anchorPostId);

                url = urlGetter.ThreadDetail(post.ThreadId, pageIndex: pageIndex, anchorPostId: anchorPostId, childPostIndex: childPostIndex);

            }

            context.Response.RedirectPermanent(url);
        }
        /// <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);
            }
        }
Example #3
0
        /// <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);
            }
        }
Example #4
0
        /// <summary>
        /// 删除群组是删除贴吧相关的
        /// </summary>
        /// <param name="group"></param>
        /// <param name="eventArgs"></param>
        private void DeleteGroup_Before(GroupEntity group, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                BarPostService            barPostService   = new BarPostService();
                BarThreadService          barThreadService = new BarThreadService();
                PagingDataSet <BarThread> barThreads       = barThreadService.Gets(group.GroupId);

                new BarSectionService().Delete(group.GroupId);
                barThreadService.DeletesBySectionId(group.GroupId);
                foreach (var barThread in barThreads)
                {
                    barPostService.DeletesByThreadId(barThread.ThreadId);
                }
            }
        }
        public AssociatedInfo GetAssociatedInfo(long associateId, string tenantTypeId = "")
        {
            BarPostService barPostService = new BarPostService();
            BarPost barPost = barPostService.Get(associateId);
            if (barPost == null)
            {
                return null;
            }

            BarThread barThread = new BarThreadService().Get(barPost.ThreadId);
            if (barThread != null)
            {
                IBarUrlGetter urlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId);
                return new AssociatedInfo()
                {
                    DetailUrl = urlGetter.ThreadDetail(barThread.ThreadId, anchorPostId: barPost.PostId),
                    Subject = barThread.Subject
                };
            }

            return null;
        }
Example #6
0
 /// <summary>
 /// 是否具有编辑BarPost的权限
 /// </summary>
 /// <param name="postId"></param>
 /// <returns></returns>
 public static bool BarPost_Edit(this Authorizer authorizer, long postId)
 {
     BarPost post = new BarPostService().Get(postId);
     if (post == null)
         return false;
     return authorizer.BarPost_Edit(post);
 }
Example #7
0
        /// <summary>
        /// 删除群组是删除贴吧相关的
        /// </summary>
        /// <param name="group"></param>
        /// <param name="eventArgs"></param>
        private void DeleteGroup_Before(GroupEntity group, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                BarPostService barPostService = new BarPostService();
                BarThreadService barThreadService = new BarThreadService();
                PagingDataSet<BarThread> barThreads = barThreadService.Gets(group.GroupId);

                new BarSectionService().Delete(group.GroupId);
                barThreadService.DeletesBySectionId(group.GroupId);
                foreach (var barThread in barThreads)
                {
                    barPostService.DeletesByThreadId(barThread.ThreadId);
                }
            }
        }
        /// <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);
            }
        }
Example #9
0
        /// <summary>
        /// 删除用户记录(删除用户时使用)
        /// </summary>
        /// <param name="userId">被删除用户</param>
        /// <param name="takeOverUserName">接管用户名</param>
        /// <param name="takeOverAll">是否接管被删除用户的所有内容</param>
        public void DeleteUser(long userId, string takeOverUserName, bool takeOverAll)
        {
            long takeOverUserId = UserIdToUserNameDictionary.GetUserId(takeOverUserName);
            IUserService userService = DIContainer.Resolve<IUserService>();
            User takeOver = userService.GetFullUser(takeOverUserId);
            BarSectionService barSectionService = new BarSectionService();
            BarThreadService barThreadService = new BarThreadService();
            BarPostService barPostService = new BarPostService();

            //删除用户时,不删除贴吧,把贴吧转让,如果没有指定转让人,那就转给网站初始管理员
            if (takeOver == null)
            {
                takeOverUserId = new SystemDataService().GetLong("Founder");
                takeOver = userService.GetFullUser(takeOverUserId);
            }

            barThreadRepository.DeleteUser(userId, takeOver, takeOverAll);
            if (takeOver != null)
            {
                if (!takeOverAll)
                {
                    barThreadService.DeletesByUserId(userId);
                    barPostService.DeletesByUserId(userId);
                }
            }
            //else
            //{
            //    barSectionService.DeletesByUserId(userId);
            //    barThreadService.DeletesByUserId(userId);
            //    barPostService.DeletesByUserId(userId);
            //}
        }
Example #10
0
        /// <summary>
        /// 删除主题帖
        /// </summary>
        /// <param name="threadId">主题帖Id</param>
        public void Delete(long threadId)
        {
            BarThread thread = barThreadRepository.Get(threadId);
            if (thread == null)
                return;

            EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Delete()));

            BarSectionService barSectionService = new BarSectionService();
            BarSection barSection = barSectionService.Get(thread.SectionId);
            if (barSection != null)
            {
                //帖子标签
                TagService tagService = new TagService(TenantTypeIds.Instance().BarThread());
                tagService.ClearTagsFromItem(threadId, barSection.SectionId);

                //帖子分类
                CategoryService categoryService = new CategoryService();
                categoryService.ClearCategoriesFromItem(threadId, barSection.SectionId, TenantTypeIds.Instance().BarThread());
            }

            //删除回帖
            BarPostService barPostService = new BarPostService();
            barPostService.DeletesByThreadId(threadId);

            //删除推荐记录
            RecommendService recommendService = new RecommendService();
            recommendService.Delete(threadId, TenantTypeIds.Instance().BarThread());

            int affectCount = barThreadRepository.Delete(thread);

            if (affectCount > 0)
            {
                //更新帖吧的计数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, -1, true);
                countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1, true);

                if (thread.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    //群组内容计数-1
                    OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                    groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), -1);
                }
                else if (thread.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数-1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1);
                }
                EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Delete()));
                EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(thread.AuditStatus, null));
            }

            //BarThread删除可能影响的:
            //1、附件 (看到了)
            //2、BarPost(看到了)
            //3、BarRating(看到了)
            //4、相关计数对象(看到了)
            //5、用户在应用中的数据(看到了)
            //6、@用户(看到了)
        }
Example #11
0
 /// <summary>
 /// 帖子的详细显示页
 /// </summary>
 /// <param name="siteUrls"></param>
 /// <param name="threadId">帖子的id</param>
 /// <param name="pageIndex">回复内容的id</param>
 /// <param name="onlyLandlord">是否只看楼主</param>
 /// <param name="sortBy">回帖的排序方式</param>
 /// <param name="anchorPostId">回帖Id锚点</param>
 /// <param name="isAnchorPostList">是否定位到回帖列表</param>
 /// <param name="childPostIndex">自己回复的列表页码</param>
 /// <returns>帖子的详细显示链接</returns>
 public static string ThreadDetail(this SiteUrls siteUrls, long threadId, bool onlyLandlord = false, SortBy_BarPost sortBy = SortBy_BarPost.DateCreated, int? pageIndex = 1, long? anchorPostId = null, bool isAnchorPostList = false, long? childPostIndex = null)
 {
     RouteValueDictionary routeValueDictionary = new RouteValueDictionary();
     routeValueDictionary.Add("threadId", threadId);
     if (pageIndex.HasValue && pageIndex != 1)
         routeValueDictionary.Add("pageIndex", pageIndex);
     if (onlyLandlord)
         routeValueDictionary.Add("onlyLandlord", onlyLandlord);
     if (sortBy == SortBy_BarPost.DateCreated_Desc)
         routeValueDictionary.Add("sortBy", sortBy);
     string anchor = string.Empty;
     if (childPostIndex.HasValue && childPostIndex > 1)
     {
         BarPost post = new BarPostService().Get(anchorPostId ?? 0);
         if (post.ParentId > 0)
             routeValueDictionary.Add("postId", post.ParentId);
         else
             routeValueDictionary.Add("postId", anchorPostId);
         routeValueDictionary.Add("childPostIndex", childPostIndex);
     }
     if (anchorPostId.HasValue && anchorPostId.Value > 0)
         anchor = "#" + anchorPostId;
     else if (isAnchorPostList == true)
         anchor = "#reply";
     return CachedUrlHelper.RouteUrl("Channel_Bar_ThreadDetail", routeValueDictionary) + anchor;
 }
Example #12
0
        /// <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);
            }
        }
Example #13
0
        /// <summary>
        /// 转换成BarPost类型
        /// </summary>
        /// <returns></returns>
        public BarPost AsBarPost()
        {
            BarThread thread = new BarThreadService().Get(this.ThreadId);

            BarPostService service = new BarPostService();
            BarPost post = null;
            //编辑的情况
            if (this.PostId.HasValue)
            {
                post = service.Get(this.PostId ?? 0);
                if (post == null)
                    return null;
            }
            else
            {
                //创建的情况
                post = BarPost.New();
                post.AuditStatus = AuditStatus.Success;
                post.TenantTypeId = thread.TenantTypeId;
                post.ThreadId = this.ThreadId;
                if (UserContext.CurrentUser != null)
                {
                    post.UserId = UserContext.CurrentUser.UserId;
                    post.Author = UserContext.CurrentUser.DisplayName;
                }
                else
                {
                    post.UserId = 0;
                    post.Author = "匿名用户";
                }
                post.OwnerId = thread == null ? 0 : thread.OwnerId;
                post.SectionId = thread == null ? 0 : thread.SectionId;
                post.ParentId = this.ParentId;
            }

            if (!string.IsNullOrEmpty(this.Body))
            {
                post.Body = this.Body;
            }
            else
            {
                this.MultilineBody = WebUtility.HtmlEncode(this.MultilineBody);
                this.MultilineBody = new EmotionService().EmoticonTransforms(this.MultilineBody);
                post.Body = this.MultilineBody;
            }
            return post;
        }