public async Task <ActionResult <ArticleDTO> > GetArticle(int index) { ArticleDTO ArticleDTO; Article article = await articleService.GetArticleByIdAsync(index);//走索引所以不需要redis缓存 if (article != null) { Dictionary <string, string> dir = StringHelper.SplitArticleContent(article.ArticleContent); for (int i = 0; i < dir.Count; i++) { string value = dir.ElementAt(i).Key; dir[value] = (await fileAttachmentService.GetFilePathById(Guid.Parse(value))); } article.ArticleVisits++;//浏览数添加 await articleService.AlterEntityAsync(article); article.ArticleContent = StringHelper.ArticleContentReplace(article.ArticleContent, dir); ArticleDTO = await articleMapper.MapperToDTOAsync(article); } else { ArticleDTO = null; } return(Ok(ArticleDTO)); }
public async Task <List <ArticleDTO> > MapperToDTOsAsync(List <Article> articles) { List <ArticleDTO> ArticleDTO = _mapper.Map <List <ArticleDTO> >(articles); foreach (var item in ArticleDTO) { List <Tag> tags = await _service.GetTagsIdByArticleId(item.ArticleId); item.ArticleTags = tags.Select(a => a.TagName).ToArray(); item.ArticleCreatedBy = "Sandman"; item.ArticleContent = StringHelper.StringTruncat(item.ArticleContent, 200, "\r\n....", out int lastLength); item.ArticleTextCount = lastLength; item.ArticleReadTime = lastLength / 250; item.ArticleImage = (await _fileService.GetFilePathById(Guid.Parse(item.ArticleImage))).Substring(17); } return(ArticleDTO); }