private async Task addRelatedDataToPostDetailAsync( PostDetailDto detail, PostResultDto post ) { detail.Post = post; detail.Categories = await getCategoryItemsAsync( post.PostTypeId, post.LangId); detail.Tags = await getPostTagsAsync(post.Id); //detail.Meta = new PostMetaListDto { // LangKey = post.LangKey, // PostSlug = post.Slug, // PostTitle = post.Title, // Items = await getPostMetaAsync(postId, ) //} }
public List <LikeDto> Resolve(Post source, PostDetailDto destination, List <LikeDto> destMember, ResolutionContext context) { var likes = _uow.Likes.GetAll().Where(i => i.PostId == source.Id); return(_mapper.Map <IEnumerable <LikeDto> >(likes).ToList()); }
public ICollection <CommentDto> Resolve(Post source, PostDetailDto destination, ICollection <CommentDto> destMember, ResolutionContext context) { var comments = _uow.Comments.GetAll().Where(i => i.PostId == source.Id); return(_mapper.Map <IEnumerable <CommentDto> >(comments).ToList()); }
/// <summary> /// 根据URL获取文章详情 /// </summary> /// <param name="url"></param> /// <returns></returns> public async Task <ServiceResult <PostDetailDto> > GetPostDetailAsync(string url) { return(await _blogCacheService.GetPostDetailAsync(url, async() => { var result = new ServiceResult <PostDetailDto>(); var post = await _postRepository.FindAsync(x => x.Url.Equals(url)); if (null == post) { result.IsFailed(ResponseText.WHAT_NOT_EXIST.FormatWith("URL", url)); return result; } var category = await _categoryRepository.GetAsync(post.CategoryId); var tags = from postTags in await _postTagRepository.GetListAsync() join tag in await _tagRepository.GetListAsync() on postTags.TagId equals tag.Id where postTags.PostId.Equals(post.Id) select new TagDto { TagName = tag.TagName, DisplayName = tag.DisplayName }; var previous = _postRepository.Where(x => x.CreationTime > post.CreationTime).Take(1).FirstOrDefault(); var next = _postRepository.Where(x => x.CreationTime < post.CreationTime) .OrderByDescending(x => x.CreationTime).Take(1).FirstOrDefault(); var postDetail = new PostDetailDto { Title = post.Title, Author = post.Author, Url = post.Url, Html = post.Html, Markdown = post.Markdown, CreationTime = post.CreationTime.TryToDateTime(), Category = new CategoryDto { CategoryName = category.CategoryName, DisplayName = category.DisplayName }, Tags = tags, Previous = previous == null ? null : new PostForPagedDto { Title = previous.Title, Url = previous.Url }, Next = next == null ? null : new PostForPagedDto { Title = next.Title, Url = next.Url } }; result.IsSuccess(postDetail); return result; })); }