Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BlogTemplate/Models/BlogDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void AppendPostInfo(Post post, XElement rootNode)
rootNode.Add(new XElement("LastModified", post.LastModified.ToString("o")));
rootNode.Add(new XElement("IsPublic", post.IsPublic.ToString()));
rootNode.Add(new XElement("Excerpt", post.Excerpt));
rootNode.Add(new XElement("EnableComments", post.EnableComments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have to convert this to a string first? Like post.EnableComments.ToString()? That is what we were doing for IsPublic, but maybe it's not necessary.

}

public void SavePost(Post post)
Expand Down Expand Up @@ -260,6 +261,7 @@ public Post CollectPostInfo(string expectedFilePath)
LastModified = DateTimeOffset.Parse(doc.Root.Element("LastModified").Value),
IsPublic = Convert.ToBoolean(doc.Root.Element("IsPublic").Value),
Excerpt = doc.Root.Element("Excerpt").Value,
EnableComments = Convert.ToBoolean(doc.Root.Element("EnableComments")?.Value),
};
post.Comments = GetAllComments(doc);
return post;
Expand Down
1 change: 1 addition & 0 deletions BlogTemplate/Models/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class Post
public bool IsPublic { get; set; }
public string Excerpt { get; set; }
public int ExcerptMaxLength { get; } = 140;
public bool EnableComments { get; set; }
}
}
8 changes: 8 additions & 0 deletions BlogTemplate/Pages/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
<label for="Excerpt" class="secondaryField">Excerpt (Optional)</label>
<textarea class="form-control" placeholder="" asp-for="EditedPost.Excerpt"></textarea>
</div>
<div class="form-group col-md-12">
<div class="checkbox">
<label asp-for="EditedPost.EnableComments">
<input asp-for="EditedPost.EnableComments" />
@Html.DisplayNameFor(m => m.EditedPost.EnableComments)
</label>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="save" class="btn btn-primary btn-sm" value="Save Draft" asp-page-handler="SaveDraft" />
<input type="submit" name="publish" class="btn btn-primary btn-sm" value="Publish" asp-page-handler="Publish" />
Expand Down
5 changes: 4 additions & 1 deletion BlogTemplate/Pages/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void OnGet([FromRoute] int id)
Title = post.Title,
Body = post.Body,
Excerpt = post.Excerpt,
EnableComments=post.EnableComments
};

if (post == null)
Expand Down Expand Up @@ -77,7 +78,7 @@ private void UpdatePost(Post post, [FromForm] bool updateSlug, bool wasPublic)
post.Title = EditedPost.Title;
post.Body = EditedPost.Body;
post.Excerpt = EditedPost.Excerpt;

post.EnableComments = EditedPost.EnableComments;
_dataStore.UpdatePost(post, wasPublic);
if (updateSlug)
{
Expand All @@ -92,6 +93,8 @@ public class EditedPostModel
[Required]
public string Body { get; set; }
public string Excerpt { get; set; }
[Display(Name = "Enable Comments")]
public bool EnableComments { get; set; }
}
}
}
8 changes: 8 additions & 0 deletions BlogTemplate/Pages/New.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<input type="file" name="files" multiple />
</div>
</div>
<div class="form-group col-md-12">
<div class="checkbox">
<label asp-for="NewPost.EnableComments">
<input asp-for="NewPost.EnableComments" />
@Html.DisplayNameFor(m => m.NewPost.EnableComments)
</label>
</div>
</div>
<div class="col-md-12">
<input type="submit" name="save" class="btn btn-primary btn-sm" value="Save Draft" asp-page-handler="SaveDraft" />
<input type="submit" name="publish" class="btn btn-primary btn-sm" value="Publish" asp-page-handler="Publish" />
Expand Down
3 changes: 3 additions & 0 deletions BlogTemplate/Pages/New.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void SavePost(NewPostViewModel newPost, bool publishPost)
Excerpt = NewPost.Excerpt,
Slug = _slugGenerator.CreateSlug(NewPost.Title),
LastModified = DateTimeOffset.Now,
EnableComments=NewPost.EnableComments
};

if (string.IsNullOrEmpty(post.Excerpt))
Expand All @@ -89,6 +90,8 @@ public class NewPostViewModel
[Required]
public string Body { get; set; }
public string Excerpt { get; set; }
[Display(Name ="Enable Comments")]
public bool EnableComments { get; set; }
}
}
}
83 changes: 50 additions & 33 deletions BlogTemplate/Pages/Post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
<h4 class="text-primary"><a asp-page="/edit" asp-route-id="@Model.Post.Id" asp-route-slug="@Model.Post.Slug">Edit Post</a></h4>
</div>
<div class="col-md-6">
<h2>Comments</h2>
@if (Model.Post.Comments.Count == 0)
@if (Model.Post.Comments.Any() || Model.Post.EnableComments)
{
<p class="text-muted">No comments yet. Be the first to comment!</p>
}
@foreach (var comment in Model.Post.Comments)
{
string cssClass = comment.IsPublic ? "" : "deletedContent";
<form id="form1" method="post">
<div class="@cssClass">
@if (comment.IsPublic)
<h2>Comments</h2>
@if (Model.Post.Comments.Count == 0)
{
<p class="text-muted">No comments yet. Be the first to comment!</p>
}
@foreach (var comment in Model.Post.Comments)
{
string cssClass = comment.IsPublic ? "" : "deletedContent";
<form id="form1" method="post">
<div class="@cssClass">
@if (comment.IsPublic)
{
<div class="well well-sm">
<h4 name="Comment-Title" class="commentTitle">@comment.AuthorName</h4>
Expand All @@ -42,9 +44,9 @@
<input type="submit" name="delete" class="btn btn-default btn-sm" value="Delete Comment" asp-page="ManageComment" asp-page-handler="DeleteComment" />
</div>

}
else
{
}
else
{
<div class="well well-sm">
<del class="delete-header">
<h4 name="Comment-Title" class="commentTitle">@comment.AuthorName</h4>
Expand All @@ -56,41 +58,45 @@
<input type="hidden" name="slug" value="@Model.Post.Slug" />
<input type="submit" name="delete" class="btn btn-default btn-sm" value="Republish Comment" asp-page="ManageComment" asp-page-handler="UndeleteComment" />
</div>
}
</div>
</form>
}
</div>
</form>
}
}
</div>
}
else
{
<div class="col-md-6">
<h2>Comments</h2>
@if (Model.Post.Comments.Count == 0)
{
<p class="text-muted">No comments yet. Be the first to comment!</p>
}
@foreach (var comment in Model.Post.Comments)
@if (Model.Post.Comments.Any() || Model.Post.EnableComments)
{
@if (comment.IsPublic)
<h2>Comments</h2>
@if (Model.Post.Comments.Count == 0)
{
<form id="form1" method="post">
<div class="well well-sm">
<h4 name="Comment-Title" class="commentTitle">@comment.AuthorName</h4>
<h6 name="Comment-Date" class="commentDate">@comment.PubDate.ToString("MMM dd, yyyy")</h6>
<p name="Comment-Body" class="commentBody">@comment.Body</p>
<input type="hidden" name="commentId" id="commentId" value="@comment.UniqueId" />
<input type="hidden" name="slug" value="@Model.Post.Slug" />
</div>
</form>
<p class="text-muted">No comments yet. Be the first to comment!</p>
}
@foreach (var comment in Model.Post.Comments)
{
@if (comment.IsPublic)
{
<form id="form1" method="post">
<div class="well well-sm">
<h4 name="Comment-Title" class="commentTitle">@comment.AuthorName</h4>
<h6 name="Comment-Date" class="commentDate">@comment.PubDate.ToString("MMM dd, yyyy")</h6>
<p name="Comment-Body" class="commentBody">@comment.Body</p>
<input type="hidden" name="commentId" id="commentId" value="@comment.UniqueId" />
<input type="hidden" name="slug" value="@Model.Post.Slug" />
</div>
</form>

}
}
}
</div>
}

<hr class="commentsDivider" />
@if (Model.Post.IsPublic)
@if (Model.Post.IsPublic && Model.Post.EnableComments)
{
<div class="col-sm-6" style="height:6px;"></div>
<div class="add-comment-form">
Expand All @@ -115,4 +121,15 @@
</div>
</div>
}
@if (!Model.Post.EnableComments)
{
<div class="row">
<div class="col-md-12">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">&times;</button>
Comments are disabled for this post.
</div>
</div>
</div>
}
</article>