CmsKit - Include Author in BlogPost for EfCore

pull/7845/head
enisn 5 years ago
parent 1f2c9f5f16
commit 923511ef39

@ -45,7 +45,11 @@ namespace Volo.CmsKit.Blogs
public async Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount,
string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
{
var queryable = (await WithDetailsAsync())
var dbContext = await GetDbContextAsync();
var blogPostsDbSet = dbContext.Set<BlogPost>();
var usersDbSet = dbContext.Set<CmsUser>();
var queryable = blogPostsDbSet
.Where(x => x.BlogId == blogId);
if (!sorting.IsNullOrWhiteSpace())
@ -53,10 +57,21 @@ namespace Volo.CmsKit.Blogs
queryable = queryable.OrderBy(sorting);
}
return await queryable
.Skip(skipCount)
.Take(maxResultCount)
.ToListAsync(GetCancellationToken());
var combinedResult = await queryable
.Join(
usersDbSet,
o => o.AuthorId,
i => i.Id,
(blogPost,user) => new { blogPost, user })
.Skip(skipCount)
.Take(maxResultCount)
.ToListAsync();
return combinedResult.Select(s =>
{
s.blogPost.Author = s.user;
return s.blogPost;
}).ToList();
}
public async Task<bool> SlugExistsAsync(Guid blogId, [NotNull] string slug,
@ -64,22 +79,8 @@ namespace Volo.CmsKit.Blogs
{
Check.NotNullOrEmpty(slug, nameof(slug));
return await (await WithDetailsAsync()).AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug,
return await (await GetDbSetAsync()).AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug,
GetCancellationToken(cancellationToken));
}
public override async Task<IQueryable<BlogPost>> WithDetailsAsync()
{
var dbContext = await GetDbContextAsync();
var blogPosts = await GetDbSetAsync();
var users = dbContext.Set<CmsUser>();
//var query = blogPosts.Join(users, o => o.AuthorId, i => i.Id, (blogPost, user) => new
//BlogPost
//{
//});
return (await GetDbSetAsync());
}
}
}

@ -5,7 +5,7 @@ using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs
{
[Serializable]
public class BlogPostPublicDto : AuditedEntityWithUserDto<Guid, CmsUserDto>
public class BlogPostPublicDto : AuditedEntityDto<Guid>
{
public Guid BlogId { get; set; }
@ -14,5 +14,7 @@ namespace Volo.CmsKit.Public.Blogs
public string Slug { get; set; }
public string ShortDescription { get; set; }
public CmsUserDto Author { get; set; }
}
}

@ -16,7 +16,7 @@
@blog.Title
</abp-card-title>
<abp-card-subtitle>
@@@blog.Creator?.UserName
@@@blog.Author?.UserName
</abp-card-subtitle>
</abp-card-header>
<abp-card-body>

@ -10,11 +10,10 @@
<abp-card>
<abp-card-header>
<abp-card-title>@Model.Title</abp-card-title>
<abp-card-subtitle>@Model.Creator?.UserName</abp-card-subtitle>
<abp-card-subtitle>@Model.Author?.UserName</abp-card-subtitle>
</abp-card-header>
<abp-card-body>
@*<img src="/api/cms-kit-public/blog-posts/@Model.Id/cover-image" class="card-img-top" style="max-width:200px;max-height:200px;" onerror="this.src='https://dummyimage.com/300x200/a3a3a3/fff.png'" />*@
@await Component.InvokeAsync(typeof(ContentViewComponent), new
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,

Loading…
Cancel
Save