Browse Source

Handle null writer

pull/988/head
Halil ibrahim Kalkan 8 years ago
parent
commit
bd325988f2
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs
  2. 391
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Blogging.Tagging.Dtos; using Volo.Blogging.Tagging.Dtos;
@ -21,6 +22,7 @@ namespace Volo.Blogging.Posts
public int CommentCount { get; set; } public int CommentCount { get; set; }
[CanBeNull]
public BlogUserDto Writer { get; set; } public BlogUserDto Writer { get; set; }
public List<TagDto> Tags { get; set; } public List<TagDto> Tags { get; set; }

391
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml

@ -46,11 +46,18 @@
<div class="article-owner"> <div class="article-owner">
<div class="article-infos"> <div class="article-infos">
<div class="user-card"> <div class="user-card">
@if (Model.Post.Writer != null)
{
<a>
<img gravatar-email="@Model.Post.Writer.Email" default-image="Identicon" class="article-avatar" />
</a>
}
<a> <a>
<img gravatar-email="@Model.Post.Writer.Email" default-image="Identicon" class="article-avatar" /> @if (Model.Post.Writer != null)
</a> {
<a> <strong>@(Model.Post.Writer.UserName),</strong>
<strong> @(Model.Post.Writer == null ? "" : Model.Post.Writer.UserName)</strong>, @ConvertDatetimeToTimeAgo(Model.Post.CreationTime) }
@ConvertDatetimeToTimeAgo(Model.Post.CreationTime)
</a> </a>
<span class="vs-seperator">|</span> <span class="vs-seperator">|</span>
<a> <a>
@ -64,14 +71,14 @@
{ {
<span class="seperator">|</span> <span class="seperator">|</span>
<a asp-page="./Edit" asp-route-postId="@Model.Post.Id" asp-route-blogShortName="@Model.BlogShortName"> <a asp-page="./Edit" asp-route-postId="@Model.Post.Id" asp-route-blogShortName="@Model.BlogShortName">
<i class="fa fa-pencil"></i> @L["Edit"] <i class="fa fa-pencil"></i> @L["Edit"]
</a> </a>
} }
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Posts.Delete) || (CurrentUser.Id == Model.Post.CreatorId)) @if (await Authorization.IsGrantedAsync(BloggingPermissions.Posts.Delete) || (CurrentUser.Id == Model.Post.CreatorId))
{ {
<span class="seperator">|</span> <span class="seperator">|</span>
<a href="#" id="DeletePostLink" data-postid="@Model.Post.Id" data-blogShortName="@Model.BlogShortName"> <a href="#" id="DeletePostLink" data-postid="@Model.Post.Id" data-blogShortName="@Model.BlogShortName">
<i class="fa fa-trash"></i> @L["Delete"] <i class="fa fa-trash"></i> @L["Delete"]
</a> </a>
} }
</div> </div>
@ -95,223 +102,223 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-8 mx-auto"> <div class="col-md-8 mx-auto">
@if (Model.Post.Tags.Count > 0) @if (Model.Post.Tags.Count > 0)
{
<div class="tags">
<h5>@L["TagsInThisArticle"]</h5>
@foreach (var tag in Model.Post.Tags)
{ {
<a asp-page="/Blog/Posts/Index" asp-route-blogShortName="@Model.BlogShortName" asp-route-tagName="@tag.Name" class="tag">@tag.Name</a> <div class="tags">
<h5>@L["TagsInThisArticle"]</h5>
@foreach (var tag in Model.Post.Tags)
{
<a asp-page="/Blog/Posts/Index" asp-route-blogShortName="@Model.BlogShortName" asp-route-tagName="@tag.Name" class="tag">@tag.Name</a>
}
</div>
} }
</div>
}
@if (Model.CommentsWithReplies.Count > 0) @if (Model.CommentsWithReplies.Count > 0)
{ {
<abp-row v-align="Start"> <abp-row v-align="Start">
<abp-column size-sm="_12"> <abp-column size-sm="_12">
<p class="float-left"><i class="fa fa-comment"></i> @L["CommentWithCount", @Model.CommentCount]</p> <p class="float-left"><i class="fa fa-comment"></i> @L["CommentWithCount", @Model.CommentCount]</p>
@if (hasCommentingPermission)
{
<a abp-button="Primary" class="btn-rounded float-right active" href="#LeaveComment">@L["LeaveComment"]</a>
}
else
{
<a abp-button="Primary" class="btn-rounded float-right active" asp-page="/Account/Login" target="_blank">@L["LeaveComment"]</a>
}
</abp-column>
</abp-row>
}
<div class="comment-area">
@foreach (var commentWithRepliesDto in Model.CommentsWithReplies)
{
<div class="media">
<img gravatar-email="@commentWithRepliesDto.Comment.Writer.Email" default-image="Identicon" class="d-flex mr-3 rounded-circle comment-avatar"/>
<div class="media-body">
<h5 class="comment-owner">
@(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName)
<span class="float-right">@ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)</span>
</h5>
<p id="@commentWithRepliesDto.Comment.Id">
@commentWithRepliesDto.Comment.Text
</p>
<div class="comment-buttons font-75 bg-light">
@if (hasCommentingPermission) @if (hasCommentingPermission)
{ {
<a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id"> <a abp-button="Primary" class="btn-rounded float-right active" href="#LeaveComment">@L["LeaveComment"]</a>
<i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
</a>
} }
else
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete))
{ {
<span class="seperator">|</span> <a abp-button="Primary" class="btn-rounded float-right active" asp-page="/Account/Login" target="_blank">@L["LeaveComment"]</a>
<a href="#" class="tag deleteLink" data-deleteid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
} }
</abp-column>
</abp-row>
}
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) <div class="comment-area">
{ @foreach (var commentWithRepliesDto in Model.CommentsWithReplies)
<span class="seperator">|</span> {
<a href="#" class="tag updateLink" data-updateid="@commentWithRepliesDto.Comment.Id"> <div class="media">
<i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"] <img gravatar-email="@commentWithRepliesDto.Comment.Writer.Email" default-image="Identicon" class="d-flex mr-3 rounded-circle comment-avatar" />
</a> <div class="media-body">
} <h5 class="comment-owner">
</div> @(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName)
<span class="float-right">@ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)</span>
</h5>
<p id="@commentWithRepliesDto.Comment.Id">
@commentWithRepliesDto.Comment.Text
</p>
<div class="comment-buttons font-75 bg-light">
@if (hasCommentingPermission) @if (hasCommentingPermission)
{ {
<div class="comment-form mt-4 replyForm"> <a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id">
<div class="clearfix bg-light p-4"> <i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
<h3 class="mt-0"> </a>
@L["ReplyTo", commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName] }
</h3> @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete))
<div> {
<form method="post"> <span class="seperator">|</span>
<input name="postId" value="@Model.Post.Id" hidden/> <a href="#" class="tag deleteLink" data-deleteid="@commentWithRepliesDto.Comment.Id">
<input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden/> <i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}
<div class="form-group"> @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea> {
<span class="seperator">|</span>
<a href="#" class="tag updateLink" data-updateid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"]
</a>
}
</div>
@if (hasCommentingPermission)
{
<div class="comment-form mt-4 replyForm">
<div class="clearfix bg-light p-4">
<h3 class="mt-0">
@L["ReplyTo", commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName]
</h3>
<div>
<form method="post">
<input name="postId" value="@Model.Post.Id" hidden />
<input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden />
<div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Comment"].Value" />
<abp-button button-type="Danger" class="btn-rounded float-right replyCancelButton" text="@L["Cancel"].Value" />
</form>
</div> </div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Comment"].Value"/> </div>
<abp-button button-type="Danger" class="btn-rounded float-right replyCancelButton" text="@L["Cancel"].Value"/>
</form>
</div> </div>
</div> }
</div> @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
} {
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) <div class="comment-form mt-4 editForm">
{ <div class="clearfix bg-light p-4">
<div class="comment-form mt-4 editForm"> <div>
<div class="clearfix bg-light p-4"> <form class="editFormClass">
<div> <input name="commentId" value="@commentWithRepliesDto.Comment.Id" hidden />
<form class="editFormClass"> <div class="form-group">
<input name="commentId" value="@commentWithRepliesDto.Comment.Id" hidden/> <textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@commentWithRepliesDto.Comment.Text</textarea>
<div class="form-group"> </div>
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@commentWithRepliesDto.Comment.Text</textarea> <abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value" />
<abp-button button-type="Danger" class="btn-rounded float-right editCancelButton" text="@L["Cancel"].Value" />
</form>
</div> </div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/> </div>
<abp-button button-type="Danger" class="btn-rounded float-right editCancelButton" text="@L["Cancel"].Value"/>
</form>
</div> </div>
</div> }
</div>
}
@foreach (var reply in commentWithRepliesDto.Replies) @foreach (var reply in commentWithRepliesDto.Replies)
{ {
<div class="media"> <div class="media">
<img gravatar-email="@reply.Writer.Email" default-image="Identicon" class="d-flex mr-3 rounded-circle comment-avatar"/> <img gravatar-email="@reply.Writer.Email" default-image="Identicon" class="d-flex mr-3 rounded-circle comment-avatar" />
<div class="media-body"> <div class="media-body">
<h5 class="comment-owner"> <h5 class="comment-owner">
@(reply.Writer == null ? "" : reply.Writer.UserName) @(reply.Writer == null ? "" : reply.Writer.UserName)
<span class="float-right">@ConvertDatetimeToTimeAgo(reply.CreationTime)</span> <span class="float-right">@ConvertDatetimeToTimeAgo(reply.CreationTime)</span>
</h5> </h5>
<p id="@reply.Id"> <p id="@reply.Id">
@reply.Text @reply.Text
</p> </p>
<div class="comment-buttons font-75 bg-light"> <div class="comment-buttons font-75 bg-light">
@if (hasCommentingPermission) @if (hasCommentingPermission)
{ {
<a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id"> <a href="#" class="tag replyLink" data-relpyid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"] <i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
</a> </a>
} }
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{ {
<span class="seperator">|</span> <span class="seperator">|</span>
<a href="#" class="tag deleteLink" data-deleteid="@reply.Id"> <a href="#" class="tag deleteLink" data-deleteid="@reply.Id">
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"] <i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a> </a>
} }
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{ {
<span class="seperator">|</span> <span class="seperator">|</span>
<a href="#" class="tag updateLink" data-updateid="@reply.Id"> <a href="#" class="tag updateLink" data-updateid="@reply.Id">
<i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"] <i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"]
</a> </a>
} }
</div> </div>
@if (hasCommentingPermission) @if (hasCommentingPermission)
{ {
<div class="comment-form mt-4 replyForm"> <div class="comment-form mt-4 replyForm">
<div class="clearfix bg-light p-4"> <div class="clearfix bg-light p-4">
<h3 class="mt-0"> <h3 class="mt-0">
@L["ReplyTo", commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName] @L["ReplyTo", commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName]
</h3> </h3>
<div> <div>
<form method="post"> <form method="post">
<input name="postId" value="@Model.Post.Id" hidden/> <input name="postId" value="@Model.Post.Id" hidden />
<input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden/> <input name="repliedCommentId" value="@commentWithRepliesDto.Comment.Id" hidden />
<div class="form-group"> <div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea> <textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value" />
<abp-button button-type="Danger" class="btn-rounded float-right replyCancelButton" text="@L["Cancel"].Value" />
</form>
</div> </div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/> </div>
<abp-button button-type="Danger" class="btn-rounded float-right replyCancelButton" text="@L["Cancel"].Value"/>
</form>
</div> </div>
</div> }
</div> @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
} {
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) <div class="comment-form mt-4 editForm">
{ <div class="clearfix bg-light p-4">
<div class="comment-form mt-4 editForm"> <div>
<div class="clearfix bg-light p-4"> <form class="editFormClass">
<div> <input name="commentId" value="@reply.Id" hidden />
<form class="editFormClass"> <div class="form-group">
<input name="commentId" value="@reply.Id" hidden/> <textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@reply.Text</textarea>
<div class="form-group"> </div>
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@reply.Text</textarea> <abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value" />
<abp-button button-type="Danger" class="btn-rounded float-right editCancelButton" text="@L["Cancel"].Value" />
</form>
</div> </div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/> </div>
<abp-button button-type="Danger" class="btn-rounded float-right editCancelButton" text="@L["Cancel"].Value"/>
</form>
</div> </div>
</div> }
</div> </div>
} </div>
</div> }
</div> </div>
} </div>
</div> }
</div> </div>
}
</div>
@if (hasCommentingPermission) @if (hasCommentingPermission)
{ {
<div class="comment-form mt-4" id="LeaveComment"> <div class="comment-form mt-4" id="LeaveComment">
<div class="vs-blog-title mb-0"> <div class="vs-blog-title mb-0">
<h3>@L["LeaveComment"]</h3> <h3>@L["LeaveComment"]</h3>
</div> </div>
<div class="clearfix bg-light p-4"> <div class="clearfix bg-light p-4">
<div> <div>
<form method="post"> <form method="post">
<input name="postId" value="@Model.Post.Id" hidden/> <input name="postId" value="@Model.Post.Id" hidden />
<input name="repliedCommentId" id="repliedCommentId" hidden/> <input name="repliedCommentId" id="repliedCommentId" hidden />
<div class="form-group"> <div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea> <textarea class="form-control no-border" name="text" id="textBoxId" rows="4"></textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value" />
</form>
</div> </div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/> </div>
</form>
</div> </div>
</div> }
else
{
<a abp-button="Primary" class="btn-rounded float-right active mt-3" asp-page="/Account/Login" target="_blank">@L["LeaveComment"]</a>
}
</div> </div>
}
else
{
<a abp-button="Primary" class="btn-rounded float-right active mt-3" asp-page="/Account/Login" target="_blank">@L["LeaveComment"]</a>
}
</div>
</div> </div>
</div> </div>

Loading…
Cancel
Save