Browse Source

fix comment query

pull/19919/head
Berkan Sasmaz 2 years ago
parent
commit
0ef9d0ad26
  1. 21
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

21
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -22,7 +22,8 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
{ {
} }
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(
Guid id,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = from comment in (await GetDbSetAsync()) var query = from comment in (await GetDbSetAsync())
@ -66,8 +67,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveState, commentApproveState);
token);
if (!sorting.IsNullOrEmpty()) if (!sorting.IsNullOrEmpty())
{ {
@ -99,8 +99,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveState, commentApproveState);
token);
return await query.LongCountAsync(token); return await query.LongCountAsync(token);
} }
@ -124,8 +123,8 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
Author = user Author = user
}; };
query.WhereIf(commentApproveState == CommentApproveState.Approved, c => c.Comment.IsApproved == true); query = query.WhereIf(commentApproveState == CommentApproveState.Approved, c => c.Comment.IsApproved == true);
query.WhereIf(commentApproveState == (CommentApproveState.Approved | CommentApproveState.Waiting), c => c.Comment.IsApproved == true || c.Comment.IsApproved == null); query = query.WhereIf(commentApproveState == (CommentApproveState.Approved | CommentApproveState.Waiting), c => c.Comment.IsApproved == true || c.Comment.IsApproved == null);
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -149,7 +148,9 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(
string idempotencyToken,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken)); return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
} }
@ -161,9 +162,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveState commentApproveState = CommentApproveState.All, CommentApproveState commentApproveState = CommentApproveState.All)
CancellationToken cancellationToken = default
)
{ {
var commentDbSet = await GetDbSetAsync(); var commentDbSet = await GetDbSetAsync();
var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>(); var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>();

Loading…
Cancel
Save