Browse Source

Use async repository method in Blogging module.

pull/6985/head
maliming 5 years ago
parent
commit
af2e3fc9df
  1. 2
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs
  2. 12
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs
  3. 18
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  4. 10
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs
  5. 2
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs
  6. 8
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs
  7. 12
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs
  8. 10
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs
  9. 2
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs

2
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs

@ -17,7 +17,7 @@ namespace Volo.Blogging.Blogs
public async Task<Blog> FindByShortNameAsync(string shortName)
{
return await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName);
return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName);
}
}
}

12
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs

@ -11,14 +11,14 @@ namespace Volo.Blogging.Comments
{
public class EfCoreCommentRepository : EfCoreRepository<IBloggingDbContext, Comment, Guid>, ICommentRepository
{
public EfCoreCommentRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider)
public EfCoreCommentRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<List<Comment>> GetListOfPostAsync(Guid postId)
{
return await DbSet
return await (await GetDbSetAsync())
.Where(a => a.PostId == postId)
.OrderBy(a => a.CreationTime)
.ToListAsync();
@ -26,20 +26,20 @@ namespace Volo.Blogging.Comments
public async Task<int> GetCommentCountOfPostAsync(Guid postId)
{
return await DbSet
return await (await GetDbSetAsync())
.CountAsync(a => a.PostId == postId);
}
public async Task<List<Comment>> GetRepliesOfComment(Guid id)
{
return await DbSet
return await (await GetDbSetAsync())
.Where(a => a.RepliedCommentId == id).ToListAsync();
}
public async Task DeleteOfPost(Guid id)
{
var recordsToDelete = DbSet.Where(pt => pt.PostId == id);
DbSet.RemoveRange(recordsToDelete);
var recordsToDelete = (await GetDbSetAsync()).Where(pt => pt.PostId == id);
(await GetDbSetAsync()).RemoveRange(recordsToDelete);
}
}
}

18
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -20,24 +20,24 @@ namespace Volo.Blogging.Posts
public async Task<List<Post>> GetPostsByBlogId(Guid id)
{
return await DbSet.Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync();
return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync();
}
public Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null)
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null)
{
var query = DbSet.Where(p => blogId == p.BlogId && p.Url == url);
var query = (await GetDbSetAsync()).Where(p => blogId == p.BlogId && p.Url == url);
if (excludingPostId != null)
{
query = query.Where(p => excludingPostId != p.Id);
}
return query.AnyAsync();
return await query.AnyAsync();
}
public async Task<Post> GetPostByUrl(Guid blogId, string url)
{
var post = await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
if (post == null)
{
@ -51,18 +51,18 @@ namespace Volo.Blogging.Posts
{
if (!descending)
{
return await DbSet.Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync();
return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync();
}
else
{
return await DbSet.Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync();
return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync();
}
}
public override IQueryable<Post> WithDetails()
public override async Task<IQueryable<Post>> WithDetailsAsync()
{
return GetQueryable().IncludeDetails();
return (await GetQueryableAsync()).IncludeDetails();
}
}
}

10
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs

@ -19,27 +19,27 @@ namespace Volo.Blogging.Tagging
public async Task<List<Tag>> GetListAsync(Guid blogId)
{
return await DbSet.Where(t=>t.BlogId == blogId).ToListAsync();
return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync();
}
public async Task<Tag> GetByNameAsync(Guid blogId, string name)
{
return await DbSet.FirstAsync(t=> t.BlogId == blogId && t.Name == name);
return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name);
}
public async Task<Tag> FindByNameAsync(Guid blogId, string name)
{
return await DbSet.FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name);
return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name);
}
public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids)
{
return await DbSet.Where(t => ids.Contains(t.Id)).ToListAsync();
return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync();
}
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{
var tags = await DbSet
var tags = await (await GetDbSetAsync())
.Where(t => ids.Any(id => id == t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));

2
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs

@ -15,7 +15,7 @@ namespace Volo.Blogging.Blogs
public async Task<Blog> FindByShortNameAsync(string shortName)
{
return await GetMongoQueryable().FirstOrDefaultAsync(p => p.ShortName == shortName);
return await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName);
}
}
}

8
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs

@ -17,7 +17,7 @@ namespace Volo.Blogging.Comments
public async Task<List<Comment>> GetListOfPostAsync(Guid postId)
{
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync())
.Where(a => a.PostId == postId)
.OrderBy(a => a.CreationTime)
.ToListAsync();
@ -25,19 +25,19 @@ namespace Volo.Blogging.Comments
public async Task<int> GetCommentCountOfPostAsync(Guid postId)
{
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync())
.CountAsync(a => a.PostId == postId);
}
public async Task<List<Comment>> GetRepliesOfComment(Guid id)
{
return await GetMongoQueryable()
return await (await GetMongoQueryableAsync())
.Where(a => a.RepliedCommentId == id).ToListAsync();
}
public async Task DeleteOfPost(Guid id)
{
var recordsToDelete = GetMongoQueryable().Where(pt => pt.PostId == id);
var recordsToDelete = (await GetMongoQueryableAsync()).Where(pt => pt.PostId == id);
foreach (var record in recordsToDelete)
{

12
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs

@ -18,25 +18,25 @@ namespace Volo.Blogging.Posts
public async Task<List<Post>> GetPostsByBlogId(Guid id)
{
return await GetMongoQueryable().Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync();
return await (await GetMongoQueryableAsync()).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync();
}
public Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null)
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null)
{
var query = GetMongoQueryable().Where(p => blogId == p.BlogId && p.Url == url);
var query = (await GetMongoQueryableAsync()).Where(p => blogId == p.BlogId && p.Url == url);
if (excludingPostId != null)
{
query = query.Where(p => excludingPostId != p.Id);
}
return query.AnyAsync();
return await query.AnyAsync();
}
public async Task<Post> GetPostByUrl(Guid blogId, string url)
{
var post = await GetMongoQueryable().FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
var post = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url);
if (post == null)
{
@ -48,7 +48,7 @@ namespace Volo.Blogging.Posts
public async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false)
{
var query = GetMongoQueryable().Where(x => x.BlogId == blogId);
var query = (await GetMongoQueryableAsync()).Where(x => x.BlogId == blogId);
if (!descending)
{

10
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs

@ -20,27 +20,27 @@ namespace Volo.Blogging.Tagging
public async Task<List<Tag>> GetListAsync(Guid blogId)
{
return await GetMongoQueryable().Where(t => t.BlogId == blogId).ToListAsync();
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId).ToListAsync();
}
public async Task<Tag> GetByNameAsync(Guid blogId, string name)
{
return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstAsync();
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync();
}
public async Task<Tag> FindByNameAsync(Guid blogId, string name)
{
return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync();
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync();
}
public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids)
{
return await GetMongoQueryable().Where(t => ids.Contains(t.Id)).ToListAsync();
return await (await GetMongoQueryableAsync()).Where(t => ids.Contains(t.Id)).ToListAsync();
}
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{
var tags = await GetMongoQueryable()
var tags = await (await GetMongoQueryableAsync())
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));

2
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs

@ -17,7 +17,7 @@ namespace Volo.Blogging.Users
public async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken)
{
var query = GetMongoQueryable();
var query = await GetMongoQueryableAsync(cancellationToken);
if (!string.IsNullOrWhiteSpace(filter))
{

Loading…
Cancel
Save