示例#1
0
        public List <CommentNReplies> GetList(int postId, string postType, string openId = "")
        {
            List <CommentNReplies> comments = new List <CommentNReplies>();

            try
            {
                var dao = new CommentsDao(mysqlConnection);
                comments.AddRange(dao.GetList(postId, postType));

                if (!string.IsNullOrEmpty(openId))
                {
                    comments.AddRange(dao.GetPendingList(postId, postType, openId)); //发表评论的人可以看到自己发表但未审核的评论
                }

                //读取作者对评论的回复
                comments.ForEach(comment =>
                {
                    comment.Replies = dao.GetAuthorReplies(comment.comment_id);
                });
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(comments.OrderByDescending(comm => comm.createdAt).ToList());
        }
示例#2
0
        public CommentsAuditList GetPendingAuditList(int pageIndex = 1, int pageSize = 10, string openId = "")
        {
            CommentsAuditList result   = new CommentsAuditList();
            List <CommentsEx> comments = new List <CommentsEx>();

            try
            {
                var dao = new CommentsDao(mysqlConnection);

                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(openId))
                {
                    sb.Append($" comment_user_id='{openId}'");
                }

                comments = dao.GetAuditList(0, pageIndex, pageSize, sb.ToString());
                Int64 count = dao.GetAuditListCount(0);

                result.lists = comments;
                result.count = count;
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(result);
        }
示例#3
0
        public ResponseEntity <string> AddAuthorComments(Comments comments)
        {
            var responseEntity = new ResponseEntity <string>(true, "添加成功", string.Empty);

            try
            {
                bool success = new CommentsDao(mysqlConnection).AddAuthorComment(comments);
            }
            catch (Exception ex)
            {
                logger.Error("评论管理-添加失败!", ex);
                responseEntity = new ResponseEntity <string>(false, "添加失败", string.Empty);
            }

            return(responseEntity);
        }
示例#4
0
        public ResponseEntity <string> GetCommentsByPostID(Comments comments)
        {
            var responseEntity = new ResponseEntity <string>(true, "审核成功", string.Empty);

            try
            {
                bool success = new CommentsDao(mysqlConnection).AuditComments(comments);
            }
            catch (Exception ex)
            {
                logger.Error("评论管理-审核失败!", ex);
                responseEntity = new ResponseEntity <string>(false, "审核失败", string.Empty);
            }

            return(responseEntity);
        }
示例#5
0
        public ResponseEntity <string> Reject(int commentId)
        {
            var responseEntity = new ResponseEntity <string>(true, "拒绝成功", string.Empty);

            try
            {
                bool success = new CommentsDao(mysqlConnection).AuditReject(commentId);
            }
            catch (Exception ex)
            {
                logger.Error("评论管理-审核失败!", ex);
                responseEntity = new ResponseEntity <string>(false, "审核失败", string.Empty);
            }

            return(responseEntity);
        }
示例#6
0
        public Int64 GetPendingAuditCount()
        {
            try
            {
                var dao = new CommentsDao(mysqlConnection);

                Int64 count = dao.GetAuditListCount(0);
                return(count);
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(0);
        }
示例#7
0
        public long GetPendingCount(string openId = "")
        {
            long count = 0;

            try
            {
                var dao = new CommentsDao(mysqlConnection);
                count = dao.GetPendingCount(openId);
            }
            catch (Exception ex)
            {
                return(0);
            }

            return(count);
        }
示例#8
0
        public void GetList_GettingData_ReturnList()
        {
            var data     = CreateCommentData();
            var storMock = new Mock <IStorage>();

            storMock.Setup(x => x.GetComments(It.IsNotNull <int?>())).Returns(data);

            var sut    = new CommentsDao(storMock.Object);
            var result = sut.GetList(1, null, 0, 0, 0).ToList();

            Assert.AreEqual(data.Count, result.Count);
            Assert.AreSame(data[0], result[0]);

            result = sut.GetList(1, "Id", 1, 0, 1).ToList();
            Assert.AreEqual(data.Count, result.Count);
            Assert.AreSame(data[data.Count - 1], result[0]);
        }
示例#9
0
        public CommentsAuditList GetRejectedAuditList(int pageIndex = 1, int pageSize = 10)
        {
            CommentsAuditList result   = new CommentsAuditList();
            List <CommentsEx> comments = new List <CommentsEx>();

            try
            {
                var dao = new CommentsDao(mysqlConnection);

                comments = dao.GetAuditList(2, pageIndex, pageSize);
                Int64 count = dao.GetAuditListCount(2);

                result.lists = comments;
                result.count = count;
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(result);
        }
示例#10
0
        public List <CommentNReplies> GetListForMyProfile(int postId, string postType)
        {
            List <CommentNReplies> comments = new List <CommentNReplies>();

            try
            {
                var dao = new CommentsDao(mysqlConnection);
                comments.AddRange(dao.GetListForMyProfile(postId, postType));

                //读取作者对评论的回复
                comments.ForEach(comment =>
                {
                    comment.Replies = dao.GetAuthorReplies(comment.comment_id);
                });
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(comments.OrderByDescending(comm => comm.createdAt).ToList());
        }