public async Task <CommentModel> GetCommentAsync(string id) { if (id == null) { throw new ArgumentNullException(); } var comment = await _dBContext.Comments.Where(c => c.Id == int.Parse(id)).SingleOrDefaultAsync(); if (comment == null) { throw new NotFoundException($"没找到id为:{id}的评论"); } return(ModelEntityHelper.CommentE2M(comment)); }
public async Task <IList <CommentModel> > GetCommentsAsync(string articleId, int start, int count) { if (articleId == null) { throw new ArgumentNullException(); } IList <CommentModel> commentModels = new List <CommentModel>(); var commentsByArticleId = await _dBContext.Comments.Where(c => c.ArticleId == int.Parse(articleId)).ToListAsync(); if (commentsByArticleId == null) { throw new NotFoundException($"没找到id为:{articleId} 的文章"); } commentsByArticleId = commentsByArticleId.OrderByDescending(c => c.Id).Skip(start).Take(count).ToList(); foreach (CommentEntity ce in commentsByArticleId) { var cm = ModelEntityHelper.CommentE2M(ce); commentModels.Add(cm); } return(commentModels); }