Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// BarPost转换成<see cref="Lucene.Net.Documents.Document"/>
        /// </summary>
        /// <param name="BarPost">回帖实体</param>
        /// <returns>Lucene.Net.Documents.Document</returns>
        public static Document Convert(BarPost barPost)
        {
            Document doc = new Document();

            //索引回帖基本信息
            doc.Add(new Field(BarIndexDocument.SectionId, barPost.SectionId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.ThreadId, "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.PostId, barPost.PostId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            //如果回帖没有主题存储其主贴的主题
            if (string.IsNullOrEmpty(barPost.Subject))
            {
                string subject = barThreadService.Get(barPostService.Get(barPost.PostId).ThreadId).Subject.ToLower();
                doc.Add(new Field(BarIndexDocument.Subject, subject, Field.Store.YES, Field.Index.ANALYZED));
            }
            else
            {
                doc.Add(new Field(BarIndexDocument.Subject, barPost.Subject, Field.Store.YES, Field.Index.ANALYZED));
            }
            doc.Add(new Field(BarIndexDocument.Body, HtmlUtility.TrimHtml(barPost.GetBody(), 0).ToLower(), Field.Store.NO, Field.Index.ANALYZED));
            doc.Add(new Field(BarIndexDocument.Author, barPost.Author, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(BarIndexDocument.IsPost, "1", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.DateCreated, DateTools.DateToString(barPost.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.TenantTypeId, barPost.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED));

            return(doc);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
        public ActionResult _CreateBarPost(long ActivityId)
        {
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(Content(string.Empty));
            }
            BarPost post = barPostService.Get(activity.SourceId);

            if (post == null)
            {
                return(Content(string.Empty));
            }


            BarThread thread = barThreadService.Get(activity.ReferenceId);

            if (thread == null)
            {
                return(Content(string.Empty));
            }
            ViewData["BarThread"] = thread;


            ViewData["Attachments"] = thread.Attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault();
            ViewData["ActivityId"]  = ActivityId;
            if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar())
            {
                var    tenantType     = new TenantTypeService().Get(thread.BarSection.TenantTypeId);
                string tenantTypeName = string.Empty;
                if (tenantType != null)
                {
                    tenantTypeName = tenantType.Name;
                }
                ViewData["tenantTypeName"] = tenantTypeName;
            }
            return(View(post));
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        public ActionResult EditPost(long threadId, long?postId)
        {
            BarThread thread = barThreadService.Get(threadId);

            if (thread == null)
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有找到你要编辑的回帖",
                    Title = "没有找到回帖",
                    StatusMessageType = StatusMessageType.Error
                })));
            }
            pageResourceManager.InsertTitlePart(thread.BarSection.Name);

            BarPost post = null;

            if (postId.HasValue && postId.Value > 0)
            {
                post = barPostService.Get(postId ?? 0);
                if (!new Authorizer().BarPost_Edit(post))
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "您没有权限编辑此回帖",
                        Title = "没有权限"
                    })));
                }
                if (post == null)
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "没有找到你要编辑的回帖",
                        Title = "没有找到回帖"
                    })));
                }
                pageResourceManager.InsertTitlePart("编辑回帖");
            }
            else
            {
                string errorMessage = string.Empty;
                if (!new Authorizer().BarPost_Create(thread.SectionId, out errorMessage))
                {
                    if (UserContext.CurrentUser == null)
                    {
                        return(Redirect(SiteUrls.Instance().Login(true)));
                    }

                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = errorMessage,
                        Title = "没有权限"
                    })));
                }
                pageResourceManager.InsertTitlePart("发表回帖");
            }

            BarPostEditModel postModel = null;

            if (post != null)
            {
                postModel = post.AsEditModel();
            }
            else
            {
                postModel = new BarPostEditModel
                {
                    ThreadId = threadId,
                    PostId   = postId,
                    Subject  = thread.Subject
                }
            };

            ViewData["PostBodyMaxLength"] = barSettings.PostBodyMaxLength;

            postModel.SectionId = thread.SectionId;
            return(View(postModel));
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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;
        }