Exemplo n.º 1
0
        /// <summary>
        /// 详细页
        /// </summary>
        /// <returns></returns>
        public ActionResult Detail(CommentSearch search)
        {
            var model = new ArticleWebEntity
            {
                //public中是实时数据
                Article =
                    UserIsLogin
                        ? ArticlesPublic.GetArticleInfoById((int)search.AId)
                        : Articles.GetArticleInfoById((int)search.AId)
            };



            if (model.Article == null || model.Article.IsNull)
            {
                return(new RedirectResult(Url.Action("Tip404", "Tips")));
            }

            //非审核通过的帖子,只能自己看
            if ((model.Article.State != 1) && (CurrentUserInfo == null || CurrentUserInfo.Id != model.Article.UserId))
            {
                return(new RedirectResult(Url.Action("Tip404", "Tips")));
            }

            model.User = Users.GetUserById(model.Article.UserId);
            ViewData["HeadNavCurrent"] = model.Article.Type;
            model.CommentSearch        = search;

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Add(int id, string content)
        {
            if (id < 0)
            {
                return(Json(new JsonResultModel {
                    Message = "参数无效!"
                }));
            }
            if (string.IsNullOrEmpty(content) || content.Length < Site.Config.WebSysConfig.CommentMinLength)
            {
                return(Json(new JsonResultModel {
                    Message = "评论内容太短了!"
                }));
            }
            if (content.Length > Site.Config.WebSysConfig.CommentMaxLength)
            {
                return(Json(new JsonResultModel {
                    Message = "评论内容太长了!"
                }));
            }
            if (!CommentsPublic.CheckCanPost(CurrentUserInfo.Id, Site.Config.UserConfig.AddCommentInterval))
            {
                return(Json(new JsonResultModel {
                    Message = "操作速度太快了,喝口水再试一下!"
                }));
            }
            var articles = Articles.GetArticleInfoById(id);

            if (articles.IsCloseComment)
            {
                return(Json(new JsonResultModel {
                    Message = string.Format("评论已关闭!原因:{0}", articles.CloseCommentReason)
                }));
            }
            var comment = new CommentVModel()
            {
                UserId    = CurrentUserInfo.Id,
                AId       = id,
                IP        = Common.Fetch.Ip,
                Content   = content,
                UserAgent = Common.Fetch.UserAgent
            };
            var user = Users.GetUserById(CurrentUserInfo.Id);

            if (user == null || user.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "用户信息异常!"
                }));
            }
            var role = Roles.GetRole(user.RoleId);

            if (role == null || role.IsNull)
            {
                return(Json(new JsonResultModel {
                    Message = "角色信息异常!"
                }));
            }
            //根据角色判断是否需要审核
            comment.State = (short)(role.CommentNeedVerified ? 0 : 1);


            long cid = CommentsPublic.AddComment(comment);

            if (cid <= 0)
            {
                return(Json(new JsonResultModel {
                    Message = "评论失败!"
                }));
            }
            return(Json(new JsonResultModel <long> {
                ResultState = true, Message = "评论成功!", Body = cid
            }));
        }