diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs index 0b0e6ab1c9..f2d14c8153 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs @@ -13,7 +13,7 @@ namespace Volo.CmsKit.Admin.Comments public Guid? RepliedCommentId { get; set; } - public string AuthorUserName { get; set; } + public string Author { get; set; } public DateTime? CreationStartDate { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs index 276d58af05..df381fbc2b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; @@ -30,7 +29,7 @@ namespace Volo.CmsKit.Admin.Comments input.EntityType, input.EntityId, input.RepliedCommentId, - input.AuthorUserName, + input.Author, input.CreationStartDate, input.CreationEndDate); @@ -39,7 +38,7 @@ namespace Volo.CmsKit.Admin.Comments input.EntityType, input.EntityId, input.RepliedCommentId, - input.AuthorUserName, + input.Author, input.CreationStartDate, input.CreationEndDate, input.Sorting, diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs index 17408a95cd..8c8e777185 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs @@ -66,19 +66,15 @@ namespace Volo.CmsKit.Comments creationStartDate, creationEndDate); - query = query.OrderBy(sorting ?? "creationTime desc") - .PageBy(skipCount, maxResultCount); + if (sorting != null) + { + sorting = "comment." + sorting; + } - var query2 = from comment in query - join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id - orderby comment.CreationTime - select new CommentWithAuthorQueryResultItem - { - Comment = comment, - Author = user - }; + query = query.OrderBy(sorting ?? "comment.creationTime desc") + .PageBy(skipCount, maxResultCount); - return await query2.ToListAsync(GetCancellationToken(cancellationToken)); + return await query.ToListAsync(GetCancellationToken(cancellationToken)); } public async Task GetCountAsync( @@ -144,7 +140,7 @@ namespace Volo.CmsKit.Comments await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); } - protected virtual async Task> GetListQueryAsync( + protected virtual async Task> GetListQueryAsync( string filter = null, string entityType = null, string entityId = null, @@ -154,25 +150,30 @@ namespace Volo.CmsKit.Comments DateTime? creationEndDate = null ) { - var dbSet = await GetDbSetAsync(); - var queryable = dbSet.AsQueryable(); + var query = from comment in (await GetDbSetAsync()) + join user in (await GetDbContextAsync()).Set() + on comment.CreatorId equals user.Id + select new CommentWithAuthorQueryResultItem + { + Comment = comment, + Author = user + }; - if (string.IsNullOrEmpty(authorUsername)) + if (!string.IsNullOrWhiteSpace(authorUsername)) { - var author = await (await GetDbContextAsync()).User.FirstOrDefaultAsync(x => x.UserName == authorUsername); + var author = await (await GetDbContextAsync()).Set().FirstOrDefaultAsync(x => x.UserName == authorUsername); var authorId = author?.Id ?? Guid.Empty; - queryable.Where(x => x.CreatorId == authorId); + query = query.Where(x => x.Comment.CreatorId == authorId); } - return (dbSet) - .WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter)) - .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType.Contains(entityType)) - .WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.EntityId.Contains(entityId)) - .WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId) - .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate) - .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate); + return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter)) + .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType)) + .WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.Comment.EntityId.Contains(entityId)) + .WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId) + .WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate) + .WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index 741d3b8b83..c58b550305 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -182,15 +182,15 @@ namespace Volo.CmsKit.MongoDB.Comments { var queryable = await GetMongoQueryableAsync(cancellationToken); - if (string.IsNullOrEmpty(authorUsername)) + if (!string.IsNullOrEmpty(authorUsername)) { - var authorQuerable = (await GetDbContextAsync(cancellationToken)).Collection().AsQueryable(); + var authorQueryable = (await GetDbContextAsync(cancellationToken)).Collection().AsQueryable(); - var author = await authorQuerable.FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken); + var author = await authorQueryable.FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken); var authorId = author?.Id ?? Guid.Empty; - queryable.Where(x => x.CreatorId == authorId); + queryable = queryable.Where(x => x.CreatorId == authorId); } return queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))