Browse Source
allow filtering by user for GetCountAsync function
pull/12048/head
Musa Demir
4 years ago
No known key found for this signature in database
GPG Key ID: 117DF92322553DC8
5 changed files with
7 additions and
2 deletions
-
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs
-
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs
-
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs
-
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs
-
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs
|
|
|
@ -92,7 +92,7 @@ public class BlogPostAdminAppService : CmsKitAppServiceBase, IBlogPostAdminAppSe |
|
|
|
var blogPosts = await BlogPostRepository.GetListAsync(input.Filter, input.BlogId, input.AuthorId, |
|
|
|
input.MaxResultCount, input.SkipCount, input.Sorting); |
|
|
|
|
|
|
|
var count = await BlogPostRepository.GetCountAsync(input.Filter); |
|
|
|
var count = await BlogPostRepository.GetCountAsync(input.Filter, input.BlogId, input.AuthorId); |
|
|
|
|
|
|
|
var dtoList = blogPosts.Select(x => |
|
|
|
{ |
|
|
|
|
|
|
|
@ -12,6 +12,7 @@ public interface IBlogPostRepository : IBasicRepository<BlogPost, Guid> |
|
|
|
Task<int> GetCountAsync( |
|
|
|
string filter = null, |
|
|
|
Guid? blogId = null, |
|
|
|
Guid? authorId = null, |
|
|
|
CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task<List<BlogPost>> GetListAsync( |
|
|
|
|
|
|
|
@ -41,10 +41,12 @@ public class EfCoreBlogPostRepository : EfCoreRepository<CmsKitDbContext, BlogPo |
|
|
|
public virtual async Task<int> GetCountAsync( |
|
|
|
string filter = null, |
|
|
|
Guid? blogId = null, |
|
|
|
Guid? authorId = null, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var queryable = (await GetDbSetAsync()) |
|
|
|
.WhereIf(blogId.HasValue, x => x.BlogId == blogId) |
|
|
|
.WhereIf(authorId.HasValue, x => x.AuthorId == authorId) |
|
|
|
.WhereIf(!string.IsNullOrEmpty(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter)); |
|
|
|
|
|
|
|
var count = await queryable.CountAsync(GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
@ -42,6 +42,7 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B |
|
|
|
public virtual async Task<int> GetCountAsync( |
|
|
|
string filter = null, |
|
|
|
Guid? blogId = null, |
|
|
|
Guid? authorId = null, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var token = GetCancellationToken(cancellationToken); |
|
|
|
@ -49,6 +50,7 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B |
|
|
|
return await (await GetMongoQueryableAsync(token)) |
|
|
|
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(!string.IsNullOrWhiteSpace(filter), x => x.Title.Contains(filter) || x.Slug.Contains(filter)) |
|
|
|
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(blogId.HasValue, x => x.BlogId == blogId) |
|
|
|
.WhereIf<BlogPost, IMongoQueryable<BlogPost>>(authorId.HasValue, x => x.AuthorId == authorId) |
|
|
|
.CountAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -42,7 +42,7 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub |
|
|
|
input.SkipCount, input.Sorting); |
|
|
|
|
|
|
|
return new PagedResultDto<BlogPostPublicDto>( |
|
|
|
await BlogPostRepository.GetCountAsync(blogId: blog.Id), |
|
|
|
await BlogPostRepository.GetCountAsync(blogId: blog.Id, authorId: input.AuthorId), |
|
|
|
ObjectMapper.Map<List<BlogPost>, List<BlogPostPublicDto>>(blogPosts)); |
|
|
|
} |
|
|
|
|
|
|
|
|