Browse Source

Added check in blog view to display error messages when no blog existed.

tags/2.0.3
Teknikode 4 years ago
parent
commit
62476ab399

+ 4
- 3
Teknik/Areas/Blog/Controllers/BlogController.cs View File

@@ -44,6 +44,7 @@ namespace Teknik.Areas.Blog.Controllers
public ActionResult Blog(string username)
{
Models.Blog blog = null;
BlogViewModel model = null;
if (string.IsNullOrEmpty(username))
{
ViewBag.Title = "Teknik Blog - " + Config.Title;
@@ -63,8 +64,8 @@ namespace Teknik.Areas.Blog.Controllers
{
var foundPosts = db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.Blog.BlogId == blog.BlogId) &&
(p.Published || p.Blog.User.Username == User.Identity.Name)
);
BlogViewModel model = new BlogViewModel();
);
model = new BlogViewModel();
model.BlogId = blog.BlogId;
model.UserId = blog.UserId;
model.User = blog.User;
@@ -74,7 +75,7 @@ namespace Teknik.Areas.Blog.Controllers

return View(model);
}
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
return View(model);
}

// GET: Blogs/Details/5

+ 100
- 78
Teknik/Areas/Blog/Views/Blog/Blog.cshtml View File

@@ -25,97 +25,119 @@
@Scripts.Render("~/bundles/blog")

<div class="container">
@if (Model.BlogId != Constants.SERVERBLOGID)
@if (Model != null && Model.User != null)
{
<div class="row">
<div class="col-sm-12 blog-heading">
<h1 class="blog-title text-center">@Model.Title</h1>
<p class="lead blog-description text-center text-muted">@Model.Description</p>
if (Model.BlogId != Constants.SERVERBLOGID)
{
<div class="row">
<div class="col-sm-12 blog-heading">
<h1 class="blog-title text-center">@Model.Title</h1>
<p class="lead blog-description text-center text-muted">@Model.Description</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 text-center">
<p>
<a href="@Url.Action("Blog", "RSS", new { area = "RSS", username = Model.User.Username })"><i class="fa fa-rss fa-2x fa-border"></i></a>
</p>
<div class="row">
<div class="col-sm-12 text-center">
<p>
<a href="@Url.Action("Blog", "RSS", new { area = "RSS", username = Model.User.Username })"><i class="fa fa-rss fa-2x fa-border"></i></a>
</p>
</div>
</div>
</div>
}
@if (Model.User.Username == User.Identity.Name)
{
<div class="row">
<div class="col-sm-12 text-center">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newPost">Create Post</button>
}
if (Model.User.Username == User.Identity.Name)
{
<div class="row">
<div class="col-sm-12 text-center">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newPost">Create Post</button>
</div>
</div>
</div>
<div class="modal fade" id="newPost" tabindex="-1" role="dialog" aria-labelledby="newPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="publishPost">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="newPostLabel">Create a New Post</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="form-group col-sm-12">
<label for="blog_title"><h4>Title</h4></label>
<input class="form-control" name="blog_title" id="blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
<div class="modal fade" id="newPost" tabindex="-1" role="dialog" aria-labelledby="newPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="publishPost">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="newPostLabel">Create a New Post</h4>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="blog_post"><h4>Article</h4></label>
<textarea class="form-control wmd-input" name="blog_post" id="blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
<div class="modal-body">
<div class="row">
<div class="form-group col-sm-12">
<label for="blog_title"><h4>Title</h4></label>
<input class="form-control" name="blog_title" id="blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="blog_post"><h4>Article</h4></label>
<textarea class="form-control wmd-input" name="blog_post" id="blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="blog_submit">Create</button>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="blog_submit">Create</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="editPostForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
</div>
<div class="modal-body">
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_title"><h4>Title</h4></label>
<input class="form-control" name="edit_blog_title" id="edit_blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="editPostForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_post"><h4>Article</h4></label>
<textarea class="form-control" name="edit_blog_post" id="edit_blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
<div class="modal-body">
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_title"><h4>Title</h4></label>
<input class="form-control" name="edit_blog_title" id="edit_blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_post"><h4>Article</h4></label>
<textarea class="form-control" name="edit_blog_post" id="edit_blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="edit_submit">Save</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="edit_submit">Save</button>
</div>
</form>
</form>
</div>
</div>
</div>
</div>
}
}

<div class="blog-main" id="@Model.BlogId"></div>
<script>
var posts = @ViewBag.Config.PostsToLoad;
var start_post = 0;
loadMorePosts(start_post, posts);
start_post = start_post + posts;
</script>
if (Model.Posts != null && Model.Posts.Any())
{
<div class="blog-main" id="@Model.BlogId"></div>
<script>
var posts = @ViewBag.Config.PostsToLoad;
var start_post = 0;
loadMorePosts(start_post, posts);
start_post = start_post + posts;
</script>
}
else
{
<div class="row">
<div class="col-sm-12 text-center">
<h2>There are currently no articles.</h2>
</div>
</div>
}
}
else
{
<div class="row">
<div class="col-sm-12 text-center">
<h2>That blog does not exist!</h2>
</div>
</div>
}
</div>

Loading…
Cancel
Save