Exemplo n.º 1
0
        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="NewsId">新闻Id</param>
        /// <param name="Contents">评论内容</param>
        /// <returns>响应实体模型</returns>
        public ResponseModel AddComment(int NewsId, string Contents)
        {
            int n = newsCommentRepsitory.AddComment(NewsId, Contents);

            if (n > 0)
            {
                return(new ResponseModel
                {
                    code = 200,
                    message = "添加成功",
                    data = new {
                        contents = Contents,
                        floor = "#" + (newsCommentRepsitory.GetCommentCountByNewsId(NewsId)),
                        addTime = DateTime.Now
                    }
                });
            }
            return(new ResponseModel {
                code = 0, message = "添加评论失败"
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取页面新闻
        /// </summary>
        /// <returns>响应实体模型</returns>
        public ResponseModel GetHomeNews()
        {
            List <News> list  = newsRepository.GetAllDesc();
            var         lists = new List <NewsModel>();

            foreach (var item in list)
            {
                lists.Add(
                    new NewsModel
                {
                    Id           = item.Id,
                    Title        = item.Title,
                    Image        = item.Image,
                    PublishDate  = item.PublishDate.ToLongDateString(),
                    Contents     = item.Contents.Length > 50 ? item.Contents.Substring(0, 50) + "..." : item.Contents,
                    Remark       = item.Remark,
                    CommentCount = newsCommentRepsitory.GetCommentCountByNewsId(item.Id),
                }
                    );
            }
            return(new ResponseModel {
                code = 200, message = "页面新闻信息", data = lists
            });
        }