Browse Source

Use async repository method in Docs module.

pull/6985/head
maliming 6 years ago
parent
commit
4924b016a9
  1. 14
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs
  2. 14
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs
  3. 18
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs
  4. 14
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs

14
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs

@ -21,7 +21,7 @@ namespace Volo.Docs.Documents
public async Task<List<Document>> GetListByProjectId(Guid projectId,
CancellationToken cancellationToken = default)
{
return await DbSet.Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken: cancellationToken);
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken: cancellationToken);
}
public async Task<List<Document>> GetAllAsync(
@ -45,7 +45,7 @@ namespace Volo.Docs.Documents
CancellationToken cancellationToken = default)
{
var query = ApplyFilterForGetAll(
DbSet,
await GetDbSetAsync(),
projectId: projectId,
name: name,
version: version,
@ -87,7 +87,7 @@ namespace Volo.Docs.Documents
CancellationToken cancellationToken = default)
{
var query = ApplyFilterForGetAll(
DbSet,
await GetDbSetAsync(),
projectId: projectId,
name: name,
version: version,
@ -111,7 +111,7 @@ namespace Volo.Docs.Documents
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await DbSet.IncludeDetails(includeDetails)
return await (await GetDbSetAsync()).IncludeDetails(includeDetails)
.FirstOrDefaultAsync(x =>
x.ProjectId == projectId && x.Name == name && x.LanguageCode == languageCode &&
x.Version == version,
@ -127,7 +127,7 @@ namespace Volo.Docs.Documents
public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToken = default)
{
return await DbSet.Where(x => x.Id == id).SingleAsync(cancellationToken: cancellationToken);
return await (await GetDbSetAsync()).Where(x => x.Id == id).SingleAsync(cancellationToken: cancellationToken);
}
protected virtual IQueryable<Document> ApplyFilterForGetAll(
@ -148,7 +148,7 @@ namespace Volo.Docs.Documents
DateTime? lastCachedTimeMax,
CancellationToken cancellationToken = default)
{
return DbSet
return query
.WhereIf(projectId.HasValue,
d => d.ProjectId == projectId.Value)
.WhereIf(name != null,
@ -179,4 +179,4 @@ namespace Volo.Docs.Documents
d => d.LastCachedTime.Date <= lastCachedTimeMax.Value.Date);
}
}
}
}

14
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs

@ -20,7 +20,7 @@ namespace Volo.Docs.Projects
public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
var projects = await DbSet.OrderBy(sorting ?? "Id desc")
var projects = await (await GetDbSetAsync()).OrderBy(sorting ?? "Id desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync();
@ -30,8 +30,8 @@ namespace Volo.Docs.Projects
public async Task<Project> GetByShortNameAsync(string shortName)
{
var normalizeShortName = NormalizeShortName(shortName);
var project = await DbSet.FirstOrDefaultAsync(p => p.ShortName == normalizeShortName);
var project = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName);
if (project == null)
{
@ -44,13 +44,13 @@ namespace Volo.Docs.Projects
public async Task<bool> ShortNameExistsAsync(string shortName)
{
var normalizeShortName = NormalizeShortName(shortName);
return await DbSet.AnyAsync(x => x.ShortName == normalizeShortName);
return await (await GetDbSetAsync()).AnyAsync(x => x.ShortName == normalizeShortName);
}
private string NormalizeShortName(string shortName)
{
return shortName.ToLower();
}
}
}
}

18
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

@ -22,17 +22,17 @@ namespace Volo.Docs.Documents
public async Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(cancellationToken);
}
public async Task<Document> FindAsync(Guid projectId, string name, string languageCode, string version,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ProjectId == projectId &&
x.Name == name &&
x.LanguageCode == languageCode &&
x.Version == version, cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ProjectId == projectId &&
x.Name == name &&
x.LanguageCode == languageCode &&
x.Version == version, cancellationToken);
}
public async Task DeleteAsync(Guid projectId, string name, string languageCode, string version,
@ -66,7 +66,7 @@ namespace Volo.Docs.Documents
return await
ApplyFilterForGetAll(
GetMongoQueryable(),
await GetMongoQueryableAsync(cancellationToken),
projectId: projectId,
name: name,
version: version,
@ -110,7 +110,7 @@ namespace Volo.Docs.Documents
return await
ApplyFilterForGetAll(
GetMongoQueryable(),
await GetMongoQueryableAsync(cancellationToken),
projectId: projectId,
name: name,
version: version,
@ -132,7 +132,7 @@ namespace Volo.Docs.Documents
public async Task<Document> GetAsync(Guid id, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().Where(x => x.Id == id).SingleAsync(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id == id).SingleAsync(cancellationToken);
}
protected virtual IMongoQueryable<Document> ApplyFilterForGetAll(
@ -221,4 +221,4 @@ namespace Volo.Docs.Documents
return query;
}
}
}
}

14
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs

@ -21,7 +21,7 @@ namespace Volo.Docs.Projects
public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
var projects = await GetMongoQueryable().OrderBy(sorting ?? "Id desc").As<IMongoQueryable<Project>>()
var projects = await (await GetMongoQueryableAsync()).OrderBy(sorting ?? "Id desc").As<IMongoQueryable<Project>>()
.PageBy<Project, IMongoQueryable<Project>>(skipCount, maxResultCount)
.ToListAsync();
@ -31,8 +31,8 @@ namespace Volo.Docs.Projects
public async Task<Project> GetByShortNameAsync(string shortName)
{
var normalizeShortName = NormalizeShortName(shortName);
var project = await GetMongoQueryable().FirstOrDefaultAsync(p => p.ShortName == normalizeShortName);
var project = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName);
if (project == null)
{
@ -45,13 +45,13 @@ namespace Volo.Docs.Projects
public async Task<bool> ShortNameExistsAsync(string shortName)
{
var normalizeShortName = NormalizeShortName(shortName);
return await GetMongoQueryable().AnyAsync(x => x.ShortName == normalizeShortName);
return await (await GetMongoQueryableAsync()).AnyAsync(x => x.ShortName == normalizeShortName);
}
private string NormalizeShortName(string shortName)
{
return shortName.ToLower();
}
}
}
}

Loading…
Cancel
Save