Exemplo n.º 1
0
        public ActionResult Comment(CommentEditModel commentModel)
        {
            if (!ModelState.IsValid && ModelState.Keys.Contains("Captcha"))
            {
                ModelState ms = new ModelState();
                ModelState.TryGetValue("Captcha", out ms);

                if (ms != null && ms.Errors != null && ms.Errors.Count > 0)
                {
                    WebUtility.SetStatusCodeForError(Response);
                    return Json(new StatusMessageData(StatusMessageType.Error, "验证码输入错误!"));
                }
            }
            if (commentModel.ToUserId == 0 && commentModel.ParentId != 0)
            {
                var parentComment = commentService.Get(commentModel.ParentId);
                commentModel.ToUserId = parentComment.OwnerId;
            }
            if (commentModel.IsValidate && authorizer.Comment_Create(commentModel.TenantTypeId, commentModel.ToUserId))
            {
                TenantCommentSettings settings = TenantCommentSettings.GetRegisteredSettings(commentModel.TenantTypeId);
                if (!settings.EnablePrivate)
                    commentModel.IsPrivate = false;

                if (!settings.EnableComment)
                {
                    WebUtility.SetStatusCodeForError(Response);
                    return Json(new StatusMessageData(StatusMessageType.Error, "该应用没有启用评论!"));
                }

                Comment comment = commentModel.AsComment();
                if (comment.ParentId != 0)
                {
                    Comment parentComment = commentService.Get(comment.ParentId);
                    if (parentComment != null)
                        comment.IsPrivate = parentComment.IsPrivate ? true : comment.IsPrivate;
                    comment.ToUserId = parentComment.UserId;
                    comment.ToUserDisplayName = comment.Author;
                }

                if (HtmlUtility.TrimHtml(comment.Body, TextLengthSettings.TEXT_BODY_MAXLENGTH).Length > settings.MaxCommentLength)
                {
                    WebUtility.SetStatusCodeForError(Response);
                    return Json(new StatusMessageData(StatusMessageType.Error, "内容超过了允许录入的长度!"));
                }

                if (commentService.Create(comment))
                    return Json(new { commentId = comment.Id, parentId = comment.ParentId });
            }
            WebUtility.SetStatusCodeForError(Response);
            return Json(new StatusMessageData(StatusMessageType.Error, "创建留言失败了!"));
        }
Exemplo n.º 2
0
 public ActionResult _Comment(long commentedObjectId, long ownerId, string tenantTypeId, string originalAuthor = null)
 {
     CommentEditModel commentModel = new CommentEditModel
     {
         CommentedObjectId = commentedObjectId,
         OwnerId = ownerId,
         TenantTypeId = tenantTypeId
     };
     return View(commentModel);
 }
Exemplo n.º 3
0
        public ActionResult _Comment(long commentedObjectId, long ownerId, string tenantTypeId, long toUserId = 0, long? commentId = null, bool enableComment = true, string subject = null, string commentClass = null)
        {
            CommentEditModel commentModel = new CommentEditModel
            {
                ToUserId = toUserId,
                CommentedObjectId = commentedObjectId,
                OwnerId = ownerId,
                TenantTypeId = tenantTypeId,
                Subject = subject
            };

            if (commentId.HasValue)
            {
                long parentId = commentId.Value;
                Comment comment = commentService.Get(commentId.Value);
                if (comment != null)
                {
                    if (comment.ParentId != 0)
                        parentId = comment.ParentId;
                    ViewData["CommentId"] = parentId;
                    ViewData["CommentIndex"] = commentService.GetPageIndexForCommentInCommens(parentId, tenantTypeId, commentedObjectId, SortBy_Comment.DateCreated);
                    if (comment.ParentId != 0)
                        ViewData["ChildIndex"] = commentService.GetPageIndexForCommentInParentCommens(comment.Id, comment.ParentId, SortBy_Comment.DateCreatedDesc);
                }
            }

            ViewData["tenantType"] = tenantTypeId;
            ViewData["enableComment"] = enableComment;
            ViewData["CommentClass"] = commentClass;

            return View(commentModel);
        }