mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added check in blog view to display error messages when no blog existed.
This commit is contained in:
parent
cbac6d1fd3
commit
62476ab399
@ -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
|
||||
|
@ -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>
|
||||
</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>
|
||||
</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>
|
||||
</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">×</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>
|
||||
<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 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>
|
||||
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="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">×</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>
|
||||
<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>
|
||||
</form>
|
||||
<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>
|
||||
</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">×</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>
|
||||
<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 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 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">×</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>
|
||||
<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>
|
||||
</form>
|
||||
</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…
Reference in New Issue
Block a user