Beispiel #1
0
        private void BarPost_After(BarPost barPost, CommonEventArgs commonEventArgs)
        {
            if (barPost == null)
            {
                return;
            }

            if (barSearcher == null)
            {
                barSearcher = (BarSearcher)SearcherFactory.GetSearcher(BarSearcher.CODE);
            }

            //添加索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                barSearcher.InsertBarPost(barPost);
            }

            //删除索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                barSearcher.DeleteBarPost(barPost.PostId);
            }

            //更新索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                barSearcher.UpdateBarPost(barPost);
            }
        }
Beispiel #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);
        }
        private void BarPost_After(BarPost barPost, CommonEventArgs commonEventArgs)
        {
            if (barPost == null)
            {
                return;
            }

            if (barSearcher == null)
            {
                barSearcher = (BarSearcher)SearcherFactory.GetSearcher(BarSearcher.CODE);
            }

            //添加索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                barSearcher.InsertBarPost(barPost);
            }

            //删除索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                barSearcher.DeleteBarPost(barPost.PostId);
            }

            //更新索引
            if (commonEventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                barSearcher.UpdateBarPost(barPost);
            }
        }
        /// <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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 积分处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void BarPostPointModule_After(BarPost sender, AuditEventArgs eventArgs)
        {
            AuditService auditService   = new AuditService();
            bool?        auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);

            string pointItemKey       = string.Empty;
            string eventOperationType = string.Empty;

            if (auditDirection == true) //加积分
            {
                pointItemKey = PointItemKeys.Instance().CreateComment();
                if (eventArgs.OldAuditStatus == null)
                {
                    eventOperationType = EventOperationType.Instance().Create();
                }
                else
                {
                    eventOperationType = EventOperationType.Instance().Approved();
                }
            }
            else if (auditDirection == false) //减积分
            {
                pointItemKey = PointItemKeys.Instance().DeleteComment();
                if (eventArgs.NewAuditStatus == null)
                {
                    eventOperationType = EventOperationType.Instance().Delete();
                }
                else
                {
                    eventOperationType = EventOperationType.Instance().Disapproved();
                }
            }

            if (!string.IsNullOrEmpty(pointItemKey))
            {
                PointService pointService = new PointService();


                string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回帖", HtmlUtility.TrimHtml(sender.GetBody(), 32));
                pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId);
            }
        }
        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));
        }
        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));
        }
Beispiel #9
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="barPost">待更新的回帖</param>
        public void UpdateBarPost(BarPost barPost)
        {
            Document doc = BarIndexDocument.Convert(barPost);

            searchEngine.Update(doc, barPost.PostId.ToString(), BarIndexDocument.PostId);
        }
Beispiel #10
0
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="barPost">待添加的回帖</param>
 public void InsertBarPost(BarPost barPost)
 {
     InsertBarPost(new BarPost[] { barPost });
 }
Beispiel #11
0
        /// <summary>
        /// 是否具有编辑BarPost的权限
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public static bool BarPost_Edit(this Authorizer authorizer, BarPost post)
        {
            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
                return true;

            if (post == null)
                return false;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;
            if (post.UserId == currentUser.UserId)
                return true;
            BarSectionService barSectionService = new BarSectionService();
            if (authorizer.BarSection_Manage(barSectionService.Get(post.SectionId)))
                return true;

            return false;
        }
Beispiel #12
0
 /// <summary>
 /// 是否具有删除BarPost的权限
 /// </summary>
 /// <param name="postId"></param>
 /// <returns></returns>
 public static bool BarPost_Delete(this Authorizer authorizer, BarPost post)
 {
     return authorizer.BarPost_Edit(post);
 }
Beispiel #13
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;
        }
        /// <summary>
        /// 积分处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void BarPostPointModule_After(BarPost sender, AuditEventArgs eventArgs)
        {
            AuditService auditService = new AuditService();
            bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);

            string pointItemKey = string.Empty;
            string eventOperationType = string.Empty;

            if (auditDirection == true) //加积分
            {
                pointItemKey = PointItemKeys.Instance().CreateComment();
                if (eventArgs.OldAuditStatus == null)
                    eventOperationType = EventOperationType.Instance().Create();
                else
                    eventOperationType = EventOperationType.Instance().Approved();
            }
            else if (auditDirection == false) //减积分
            {
                pointItemKey = PointItemKeys.Instance().DeleteComment();
                if (eventArgs.NewAuditStatus == null)
                    eventOperationType = EventOperationType.Instance().Delete();
                else
                    eventOperationType = EventOperationType.Instance().Disapproved();
            }

            if (!string.IsNullOrEmpty(pointItemKey))
            {
                PointService pointService = new PointService();

                string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回帖", HtmlUtility.TrimHtml(sender.GetBody(), 32));
                pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId);
            }
        }
        /// <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);
            }
        }
Beispiel #16
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);
            }
        }