Ejemplo n.º 1
0
        /// <summary>
        /// 获取评论集合
        /// </summary>
        public ResponseModel GetCommentList(Expression <Func <NewsComment, bool> > where)
        {
            var comments = _db.NewsComment.Include("News").Where(where).OrderBy(c => c.AddTime).ToList();
            var response = new ResponseModel();

            response.code   = 200;
            response.result = "评论获取成功";
            response.data   = new List <CommentModel>();
            int        floor   = 1;
            HtmlToText convert = new HtmlToText();

            foreach (var comment in comments)
            {
                CommentModel cm = new CommentModel();
                cm.Id        = comment.Id;
                cm.NewsId    = comment.NewsId;
                cm.NewsName  = comment.News.Title;
                cm.UserName  = _userService.GetOneUsers(comment.UserId).data.F_RealName;
                cm.UserId    = comment.UserId;
                cm.UserImage = _userService.GetOneUsers(comment.UserId).data.F_Image;
                cm.Contents  = convert.ConvertImgByFace(comment.Contents);
                cm.AddTime   = comment.AddTime;
                cm.Love      = comment.Love;
                cm.Remark    = comment.Remark;
                cm.Floor     = "#" + floor;

                List <NewsComment>  nc    = GetRaplyComment(comment.Id);
                List <CommentReply> crlst = new List <CommentReply>();
                if (nc.Count() > 0)
                {
                    foreach (var item in nc)
                    {
                        CommentReply cr = new CommentReply();
                        cr.NewsId         = item.NewsId;
                        cr.OldId          = item.OldId;
                        cr.UserName       = _userService.GetOneUsers(item.UserId).data.F_RealName;
                        cr.ReplyUserId    = item.ReplyUserId;
                        cr.ReplyUserName  = _userService.GetOneUsers(item.ReplyUserId).data.F_RealName;
                        cr.ReplyUserImage = _userService.GetOneUsers(item.ReplyUserId).data.F_Image;
                        cr.Id             = item.Id;
                        cr.Love           = item.Love;
                        cr.Contents       = convert.ConvertImgByFace(item.Contents);
                        cr.AddTime        = item.AddTime;
                        crlst.Add(cr);
                    }
                }
                cm.crLst = crlst;
                response.data.Add(cm);
                floor++;
            }
            response.data.Reverse();
            return(response);
        }