Browse Source

Merge pull request #16747 from abpframework/issue-16746

The detail page should not give an error if a post is without an author
pull/16749/head
Engincan VESKE 3 years ago
committed by GitHub
parent
commit
db2d9da16c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 68
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml
  2. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs

68
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml

@ -147,27 +147,32 @@
} }
</div> </div>
<div class="col ps-1"> <div class="col ps-1">
<h5 class="mt-2 mb-1"> @if (Model.Post.Writer != null)
<a href="/Members/@Model.Post.Writer.UserName"> {
@if (Model.Post.Writer.Name != null && Model.Post.Writer.Surname != null) <h5 class="mt-2 mb-1">
{
<p class="fw-bold pt-2 fs-5">@Model.Post.Writer.Name @Model.Post.Writer.Surname</p> <a href="/Members/@Model.Post.Writer.UserName">
} @if (Model.Post.Writer.Name != null && Model.Post.Writer.Surname != null)
else {
<p class="fw-bold pt-2 fs-5">@Model.Post.Writer.Name @Model.Post.Writer.Surname</p>
}
else
{
<p class="fw-bold pt-2 fs-5">@Model.Post.Writer.UserName</p>
}
</a>
</h5>
<div class="position-relative">
@if (Model.Post.Writer.JobTitle != null)
{ {
<p class="fw-bold pt-2 fs-5">@Model.Post.Writer.UserName</p> <p class="fw-lighter">@Model.Post.Writer.JobTitle</p>
} }
</a> </div>
</h5> }
<div class="position-relative">
@if (Model.Post.Writer.JobTitle != null) @if (CurrentUser.Id.HasValue && CurrentUser.Id.Value == Model.Post.Writer?.Id)
{
<p class="fw-lighter">@Model.Post.Writer.JobTitle</p>
}
</div>
@if (CurrentUser.UserName == Model.Post.Writer.UserName)
{ {
<a class="fw-lighter" href="/Members/@Model.Post.Writer.UserName#edit-profile">@L["EditProfile"] <i class="fas fa-edit"></i></a> <a class="fw-lighter" href="/Members/@Model.Post.Writer?.UserName#edit-profile">@L["EditProfile"] <i class="fas fa-edit"></i></a>
} }
</div> </div>
@if (Model.LatestPosts.Count > 1) @if (Model.LatestPosts.Count > 1)
@ -185,23 +190,24 @@
<div class="article-owner"> <div class="article-owner">
<div class="article-infos"> <div class="article-infos">
<div class="user-card pt-3"> <div class="user-card pt-3">
<div class="row"> @if (post.Writer != null)
<div class="col-auto pe-1"> {
@if (post.Writer != null) <div class="row">
{ <div class="col-auto pe-1">
<a href="/Members/@post.Writer.UserName" aria-label="Go to user profile"> <a href="/Members/@post.Writer.UserName" aria-label="Go to user profile">
<img gravatar-email="@post.Writer.Email" default-image="Identicon" class="last-post-image" alt="User Avatar"/> <img gravatar-email="@post.Writer.Email" default-image="Identicon" class="last-post-image" alt="User Avatar"/>
</a> </a>
} </div>
</div>
<div class="col"> <div class="col">
<h5 class="last-post-name"> <h5 class="last-post-name">
<a href="/Members/@post.Writer.UserName"> <a href="/Members/@post.Writer!.UserName">
@(post.Writer.UserName) @(post.Writer!.UserName)
</a> </a>
</h5> </h5>
</div>
</div> </div>
</div> }
</div> </div>
</div> </div>
<div class="col mt-2"> <div class="col mt-2">

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs

@ -86,7 +86,11 @@ namespace Volo.Blogging.Pages.Blog.Posts
{ {
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl }); Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl });
PostsList = await _postAppService.GetListByUserIdAsync(Post.Writer.Id);
PostsList = Post.Writer != null
? await _postAppService.GetListByUserIdAsync(Post.Writer.Id)
: new List<PostWithDetailsDto>();
LatestPosts = await _postAppService.GetLatestBlogPostsAsync(Blog.Id, 5); LatestPosts = await _postAppService.GetLatestBlogPostsAsync(Blog.Id, 5);
CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id); CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id);
CountComments(); CountComments();

Loading…
Cancel
Save