public async Task <PagedResultDto <PostListDto> > GetPaged(GetPostsInput input) { var query = _postRepository.GetAll() //模糊搜索地址 .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), a => a.Url.Contains(input.FilterText)) //模糊搜索封面 .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), a => a.CoverImage.Contains(input.FilterText)) //模糊搜索标题 .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), a => a.Title.Contains(input.FilterText)) //模糊搜索内容 .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), a => a.Content.Contains(input.FilterText)) ; // TODO:根据传入的参数添加过滤条件 var count = await query.CountAsync(); var postList = await query .OrderBy(input.Sorting).AsNoTracking() .PageBy(input) .ToListAsync(); var postListDtos = ObjectMapper.Map <List <PostListDto> >(postList); foreach (var item in postListDtos) { var tags = await GetTagsOfPost(item.Id); item.Tags = string.Join(", ", tags.Select(p => p.Name).ToArray()); item.BlogName = AsyncHelper.RunSync(() => _blogManager.FindByIdAsync(item.BlogId)).Name; } return(new PagedResultDto <PostListDto>(count, postListDtos)); }
public async Task <PagedResultOutput <PostDto> > GetPosts(GetPostsInput input) { var postCount = await _postRepository.CountAsync(); var posts = _postRepository.GetAll().OrderByDescending(p => p.CreationTime).PageBy(input); return(new PagedResultOutput <PostDto>( postCount, posts.MapTo <List <PostDto> >() )); }
public async Task <PagedResultDto <PostDto> > GetPosts(GetPostsInput input) { var postCount = await _postRepository.CountAsync(); var posts = _postRepository.GetAll().OrderByDescending(p => p.CreationTime).PageBy(input).ToList(); posts.ForEach(post => { _postRepository.EnsurePropertyLoaded(post, p => p.Category); }); return(new PagedResultDto <PostDto>( postCount, posts.MapTo <List <PostDto> >() )); }