Exemplo n.º 1
0
        public async Task <IList <ArticleInfoModel> > GetArticleInfosAsync()
        {
            var articles = await _dBContext.Articles
                           .Include(a => a.Category)
                           .OrderByDescending(a => a.Id)
                           .ToListAsync();

            IList <ArticleInfoModel> result = new List <ArticleInfoModel>();

            foreach (ArticleEntity ae in articles)
            {
                var temp = ModelEntityHelper.ArticleE2M(ae);
                result.Add(temp);
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <ArticleInfoModel> GetArticleInfoAsync(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException();
            }
            try
            {
                var article = await _dBContext.Articles.Where(c => c.Id == int.Parse(id)).SingleOrDefaultAsync();

                if (article == null)
                {
                    throw new NotFoundException($"没找到id为:{id} 的文章");
                }
                return(ModelEntityHelper.ArticleE2M(article));
            }
            catch
            {
                throw;
            }
        }