Use async repository method in CmsKit module.

pull/6985/head
maliming 5 years ago
parent af2e3fc9df
commit cb38a0fa74

@ -28,8 +28,8 @@ namespace Volo.CmsKit.Comments
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = from comment in DbSet
join user in DbContext.Set<CmsUser>() on comment.CreatorId equals user.Id
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
select new CommentWithAuthorQueryResultItem
@ -45,7 +45,7 @@ namespace Volo.CmsKit.Comments
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await DbSet
var replies = await (await GetDbSetAsync())
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));

@ -23,9 +23,9 @@ namespace Volo.CmsKit.Pages
return FindAsync(x => x.Url == url);
}
public Task<bool> DoesExistAsync(string url)
public async Task<bool> DoesExistAsync(string url)
{
return DbSet.AnyAsync(x => x.Url == url);
return await (await GetDbSetAsync()).AnyAsync(x => x.Url == url);
}
}
}
}

@ -24,7 +24,7 @@ namespace Volo.CmsKit.Ratings
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var rating = await DbSet.FirstOrDefaultAsync(
var rating = await (await GetDbSetAsync()).FirstOrDefaultAsync(
r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId,
GetCancellationToken(cancellationToken));
@ -38,7 +38,7 @@ namespace Volo.CmsKit.Ratings
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = (
from rating in DbSet
from rating in (await GetDbSetAsync())
where rating.EntityType == entityType && rating.EntityId == entityId
group rating by rating.StarCount
into g
@ -54,4 +54,4 @@ namespace Volo.CmsKit.Ratings
return ratings;
}
}
}
}

@ -30,7 +30,7 @@ namespace Volo.CmsKit.Reactions
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName));
return await DbSet
return await (await GetDbSetAsync())
.Where(x =>
x.CreatorId == userId &&
x.EntityType == entityType &&
@ -48,7 +48,7 @@ namespace Volo.CmsKit.Reactions
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await DbSet
return await (await GetDbSetAsync())
.Where(x =>
x.CreatorId == userId &&
x.EntityType == entityType &&
@ -64,7 +64,7 @@ namespace Volo.CmsKit.Reactions
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await DbSet
return await (await GetDbSetAsync())
.Where(x =>
x.EntityType == entityType &&
x.EntityId == entityId)

@ -19,13 +19,13 @@ namespace Volo.CmsKit.Tags
{
}
public virtual Task<bool> AnyAsync(
public virtual async Task<bool> AnyAsync(
[NotNull] string entityType,
[NotNull] string name,
Guid? tenantId = null,
CancellationToken cancellationToken = default)
{
return DbSet.AnyAsync(x =>
return await (await GetDbSetAsync()).AnyAsync(x =>
x.EntityType == entityType &&
x.Name == name &&
x.TenantId == tenantId,
@ -64,12 +64,12 @@ namespace Volo.CmsKit.Tags
Guid? tenantId = null,
CancellationToken cancellationToken = default)
{
var entityTagIds = await DbContext.Set<EntityTag>()
var entityTagIds = await (await GetDbContextAsync()).Set<EntityTag>()
.Where(q => q.EntityId == entityId && q.TenantId == tenantId)
.Select(q => q.TagId)
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
var query = DbSet
var query = (await GetDbSetAsync())
.Where(x => x.EntityType == entityType &&
x.TenantId == tenantId &&
entityTagIds.Contains(x.Id));

@ -26,15 +26,15 @@ namespace Volo.CmsKit.MongoDB.Comments
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var authorsQuery = from comment in GetMongoQueryable()
join user in DbContext.CmsUsers on comment.CreatorId equals user.Id
var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
select user;
var authors = await authorsQuery.ToListAsync(GetCancellationToken(cancellationToken));
var comments = await GetMongoQueryable()
var comments = await (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType)
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
@ -53,7 +53,7 @@ namespace Volo.CmsKit.MongoDB.Comments
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await GetMongoQueryable()
var replies = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));

@ -22,10 +22,10 @@ namespace Volo.CmsKit.MongoDB.Pages
{
return FindAsync(x => x.Url == url);
}
public Task<bool> DoesExistAsync(string url)
public async Task<bool> DoesExistAsync(string url)
{
return GetMongoQueryable().AnyAsync(x => x.Url == url);
return await (await GetMongoQueryableAsync()).AnyAsync(x => x.Url == url);
}
}
}
}

@ -25,7 +25,7 @@ namespace Volo.CmsKit.MongoDB.Ratings
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var rating = await GetMongoQueryable()
var rating = await (await GetMongoQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(r => r.EntityType == entityType && r.EntityId == entityId && r.CreatorId == userId,
GetCancellationToken(cancellationToken));
@ -39,7 +39,7 @@ namespace Volo.CmsKit.MongoDB.Ratings
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = (
from rating in GetMongoQueryable()
from rating in (await GetMongoQueryableAsync(cancellationToken))
where rating.EntityType == entityType && rating.EntityId == entityId
group rating by rating.StarCount
into g
@ -55,4 +55,4 @@ namespace Volo.CmsKit.MongoDB.Ratings
return ratings;
}
}
}
}

@ -29,7 +29,7 @@ namespace Volo.CmsKit.MongoDB.Reactions
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName));
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x =>
x.CreatorId == userId &&
x.EntityType == entityType &&
@ -47,7 +47,7 @@ namespace Volo.CmsKit.MongoDB.Reactions
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x =>
x.CreatorId == userId &&
x.EntityType == entityType &&
@ -63,7 +63,7 @@ namespace Volo.CmsKit.MongoDB.Reactions
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x =>
x.EntityType == entityType &&
x.EntityId == entityId)

@ -18,13 +18,13 @@ namespace Volo.CmsKit.MongoDB.Tags
{
}
public Task<bool> AnyAsync(
public async Task<bool> AnyAsync(
[NotNull] string entityType,
[NotNull] string name,
Guid? tenantId = null,
CancellationToken cancellationToken = default)
{
return GetMongoQueryable()
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(x =>
x.EntityType == entityType &&
x.Name == name &&
@ -64,13 +64,13 @@ namespace Volo.CmsKit.MongoDB.Tags
Guid? tenantId = null,
CancellationToken cancellationToken = default)
{
var entityTagIds = await DbContext.EntityTags.AsQueryable()
var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable()
.Where(q => q.EntityId == entityId && q.TenantId == tenantId)
.Select(q => q.TagId)
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
var query = GetMongoQueryable()
.Where(x =>
var query = (await GetMongoQueryableAsync(cancellationToken))
.Where(x =>
x.EntityType == entityType &&
x.TenantId == tenantId &&
entityTagIds.Contains(x.Id));

Loading…
Cancel
Save