コード例 #1
0
        public ActionResult Comment(MicroblogCommentEditModel model)
        {
            string message = string.Empty;
            if (ModelState.HasBannedWord(out message))
            {
                return Json(new StatusMessageData(StatusMessageType.Error, message));
            }

            IUser currentUser = UserContext.CurrentUser;
            long userId = microblogService.Get(model.CommentedObjectId).UserId;
            //被评论用户的隐私判断

            if (!privacyService.Validate(userId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Comment()))
            {
                return Json(new StatusMessageData(StatusMessageType.Hint, "该用户不允许你评论他的内容!"));
            }

            CommentService commentService = new CommentService();
            if (model.IsValidate)
            {
                Comment comment = model.AsComment();
                //todo:bianchx,by zhengw:可以考虑在model.AsComment方法中处理IsPrivate问题
                if (comment.ParentId != 0)
                {
                    Comment parentComment = commentService.Get(comment.ParentId);
                    if (parentComment != null)
                        comment.IsPrivate = parentComment.IsPrivate ? true : comment.IsPrivate;
                }

                if (commentService.Create(comment))
                {
                    if (model.CommentOriginalAuthor)
                    {
                        MicroblogEntity entity = microblogService.Get(comment.CommentedObjectId);
                        //todo:bianchx,by zhengw:应判断entity.User是否为null

                        if (entity != null)
                        {
                            Comment originalAuthorComment = model.AsComment();
                            entity = entity.OriginalMicroblog;
                            if (entity != null)
                            {
                                originalAuthorComment.ToUserId = entity.UserId;
                                originalAuthorComment.ToUserDisplayName = entity.User.DisplayName;
                                originalAuthorComment.CommentedObjectId = entity.MicroblogId;
                                commentService.Create(originalAuthorComment);
                            }
                        }
                    }
                    if (model.ForwardMicrobo)
                    {
                        MicroblogEntity microblogEntity = microblogService.Get(model.CommentedObjectId);
                        if (microblogEntity != null)
                        {
                            MicroblogEntity microblog = MicroblogEntity.New();
                            microblog.Body = "转发微博";
                            microblog.Author = currentUser.DisplayName;
                            microblog.UserId = currentUser.UserId;
                            microblog.OwnerId = currentUser.UserId;
                            microblog.TenantTypeId = TenantTypeIds.Instance().User();

                            microblog.ForwardedMicroblogId = microblogEntity.MicroblogId;
                            microblog.OriginalMicroblogId = microblogEntity.OriginalMicroblogId > 0 ? microblogEntity.OriginalMicroblogId : microblog.ForwardedMicroblogId;

                            long toUserId = microblog.UserId;

                            MicroblogEntity entity = microblogService.Get(microblog.OriginalMicroblogId);
                            long toOriginalUserId = entity == null ? 0 : entity.UserId;

                            long microblogId = 0;
                            microblogService.Forward(microblog, false, false, toUserId, toOriginalUserId, out microblogId);
                        }
                    }
                    return Json(new { commentid = comment.Id });
                }
            }
            WebUtility.SetStatusCodeForError(Response);
            return Json(new StatusMessageData(StatusMessageType.Error, "创建留言失败了!"));
        }
コード例 #2
0
 //todo:bianchx,by zhengw:ownerId是什么?觉得没必要传递originalAuthor,可以通过commentedObjectId获取到
 /// <summary>
 /// 评论
 /// </summary>
 /// <returns></returns>
 public ActionResult _Comment(long commentedObjectId, long ownerId, string tenantTypeId, string originalAuthor = null, string subject = null)
 {
     MicroblogCommentEditModel commentModel = new MicroblogCommentEditModel
     {
         CommentedObjectId = commentedObjectId,
         OwnerId = ownerId,
         TenantTypeId = tenantTypeId,
         OriginalAuthor = originalAuthor,
         Subject = subject
     };
     return View(commentModel);
 }