Esempio n. 1
0
        public ResponseModel AddComments(AddComments comment)
        {
            var news = _newsService.GetoneNews(comment.NewsId);

            if (news.code == 0)
            {
                return new ResponseModel {
                           code = 0, result = "评价的新闻不存在"
                }
            }
            ;
            var com = new NewsComment {
                AddTime = DateTime.Now, NewsId = comment.NewsId, Contents = comment.Contents
            };

            _db.NewsComment.Add(com);
            int i = _db.SaveChanges();

            if (i > 0)
            {
                return(new ResponseModel {
                    code = 200, result = "评论添加成功", data = new
                    {
                        contents = comment.Contents,
                        floor = '#' + news.data.CommentCount + 1,
                        addTime = DateTime.Now
                    }
                });
            }

            return(new ResponseModel {
                code = 0, result = "评论添加失败"
            });
        }
Esempio n. 2
0
        /// <summary>
        /// 添加评论  --  用于前端
        /// </summary>
        public ResponseModel AddComment(AddComment comment)
        {
            var news = _newsService.GetoneNews(comment.NewsId);

            if (news.code == 0)
            {
                return new ResponseModel {
                           code = 0, result = "新闻不存在"
                }
            }
            ;
            var com = new NewsComment {
                AddTime = DateTime.Now, NewsId = comment.NewsId, Contents = comment.Contents
            };

            _db.NewsComment.Add(com);
            int i = _db.SaveChanges();

            if (i > 0)
            {
                return(new ResponseModel
                {
                    code = 200,
                    result = "新闻评论添加成功",
                    // 目的在于非刷新状态下完成评论可视化
                    data = new
                    {
                        // 显示评论内容
                        contents = comment.Contents,
                        // 评论楼层,根据评论数量的情况盖楼,第一个评论的是1楼
                        floor = "#" + (Convert.ToInt32(news.data.CommentCount) + 1),
                        // 显示评论时间
                        addTime = DateTime.Now
                    }
                });
            }
            return(new ResponseModel {
                code = 0, result = "新闻评论添加失败"
            });
        }
Esempio n. 3
0
 /// <summary>
 /// 添加评论
 /// </summary>
 public  ResponseModel AddComment(AddComment comment)
 {
     var news = _newsService.GetoneNews(comment.NewsId);
     if (news.code == 0)
         return new ResponseModel { code = 0, result = "新闻不存在" };
     var com = new NewsComment { AddTime = DateTime.Now, NewsId = comment.NewsId, Contents = comment.Contents };
     _db.NewsComment.Add(com);
     int i = _db.SaveChanges();
     if (i > 0)
     {
         return new ResponseModel
         {
             code = 200,
             result = "新闻评论添加成功",
             data = new
             {
                 contents = comment.Contents,
                 floor = "#" + (Convert.ToInt32(news.data.CommentCount) + 1),
                 addTime = DateTime.Now
             }
         };
     }
     return new ResponseModel { code = 0, result = "新闻评论添加失败" };
 }