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 Create(CreatePostInput input) { // Is the user the author of the blog? var blog = await _blogManager.FindByIdAsync(input.BlogId); if (blog?.AuthorId != AbpSession.UserId && AbpSession.UserId != input.AuthorId) { return; } var post = ObjectMapper.Map <Post>(input); await _postManager.CreateAsync(post); }
public async Task <BlogListOutput> GetBlogById(int blogId) { return(ObjectMapper.Map <BlogListOutput>(await _blogManager.FindByIdAsync(blogId))); }