public ActionResult EditPost(BarPostEditModel post)
        {

            //1.没有判断创建、编辑回帖的权限

            //2.代码组织乱,先判断异常情况,正常情况留至最后处理;

            //3.如果返回错误信息情况较多,可以抽出一个私有方法(已帮忙写好,查看StatusMessage方法),在其内部判断是同步还是异步;

            BarPost barPost = post.AsBarPost();
            if (barPost == null)
                return StatusMessage(StatusMessageType.Error, "没有找到编辑的内容");

            string errorMessage = string.Empty;
            if (ModelState.HasBannedWord(out errorMessage))
            {
                return StatusMessage(StatusMessageType.Error, errorMessage);
            }

            if (post.PostId.HasValue && post.PostId.Value > 0)
            {
                if (!authorizer.BarPost_Edit(post.PostId ?? 0))
                    return StatusMessage(StatusMessageType.Error, "您没有权限编辑此回帖");
                barPostService.Update(barPost, UserContext.CurrentUser.UserId);
                if (Request.IsAjaxRequest())
                    return Json(new { PostId = barPost.PostId });
                else
                    return Redirect(SiteUrls.Instance().ThreadDetailGotoPost(barPost.PostId));
            }
            else
            {
                StatusMessageData hint = null;
                if (!authorizer.BarPost_Create(barPost.SectionId, out errorMessage))
                    return StatusMessage(StatusMessageType.Error, errorMessage);
                bool isCreat = barPostService.Create(barPost);
                if (barPost.AuditStatus == AuditStatus.Pending)
                {
                    hint = new StatusMessageData(StatusMessageType.Hint, "您的回复需要通过审核");
                }
                if (isCreat)
                {
                    if (Request.IsAjaxRequest())
                        return Json(new { PostId = barPost.PostId, auditStatus = hint });
                    else
                        return Redirect(SiteUrls.Instance().ThreadDetailGotoPost(barPost.PostId));
                }
                return StatusMessage(StatusMessageType.Error, "创建失败");
            }
        }
        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));
        }
        public ActionResult EditPost(long threadId, long? postId = null)
        {
            BarThread thread = barThreadService.Get(threadId);

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

            BarPost post = null;
            if (postId.HasValue)
            {
                post = barPostService.Get(postId ?? 0);
                if (!authorizer.BarPost_Edit(post))
                {
                    return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "您没有权限编辑此回帖",
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }
            else
            {


                string errorMessage = string.Empty;
                if (!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 = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }
            if (postId.HasValue && post == null)
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有找到你要编辑的回帖",
                    Title = "没有找到回帖",
                    StatusMessageType = StatusMessageType.Hint
                }));
            }





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

                string body = Request.QueryString.Get<string>("MultilineBody", null);

                if (!string.IsNullOrEmpty(body))
                    postModel.Body = body = new EmotionService().EmoticonTransforms(body);
            }
            ViewData["PostBodyMaxLength"] = barSettings.PostBodyMaxLength;

            postModel.SectionId = thread.SectionId;
            return View(postModel);
        }