Browse Source

Fixed server specific blog viewing (Set to be first blog in DB)

master
Teknikode 7 years ago
parent
commit
a4a11d7076
  1. 23
      Teknik/Areas/Blog/Controllers/BlogController.cs
  2. 2
      Teknik/Areas/Blog/ViewModels/BlogViewModel.cs
  3. 7
      Teknik/Areas/Blog/Views/Blog/Blog.cshtml
  4. 2
      Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml
  5. 2
      Teknik/Areas/Home/Controllers/HomeController.cs
  6. 13
      Teknik/Configuration/Config.cs
  7. 2
      Teknik/Helpers/Constants.cs
  8. 1
      Teknik/Views/Shared/_Layout.cshtml
  9. 4
      Teknik/Web.config

23
Teknik/Areas/Blog/Controllers/BlogController.cs

@ -25,33 +25,40 @@ namespace Teknik.Areas.Blog.Controllers @@ -25,33 +25,40 @@ namespace Teknik.Areas.Blog.Controllers
{
Models.Blog blog = null;
BlogViewModel model = null;
// The blog is the main site's blog
if (string.IsNullOrEmpty(username))
{
ViewBag.Title = "Teknik Blog - " + Config.Title;
blog = db.Blogs.Find(Constants.SERVERBLOGID);
var blogs = db.Blogs.Include("User").Where(p => (p.BlogId == Constants.SERVERBLOGID));
if (blogs != null && blogs.Any())
{
blog = blogs.First();
blog.Title = Config.BlogTitle;
blog.Description = Config.BlogDescription;
}
}
else
else // A user specific blog
{
var blogs = db.Blogs.Include("User").Where(p => p.User.Username == username);
var blogs = db.Blogs.Include("User").Where(p => p.User.Username == username && p.BlogId != Constants.SERVERBLOGID);
if (blogs.Any())
{
blog = blogs.First();
ViewBag.Title = blog.User.Username + "'s Blog - " + Config.Title;
}
}
// find the post specified
// find the blog specified
if (blog != null)
{
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)
).OrderByDescending(p => p.DatePosted);
var foundPosts = (User.IsInRole("Admin")) ? db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.BlogId == blog.BlogId))
: db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.BlogId == blog.BlogId) &&
(p.Published || p.Blog.User.Username == User.Identity.Name));
model = new BlogViewModel();
model.BlogId = blog.BlogId;
model.UserId = blog.UserId;
model.User = blog.User;
model.Title = blog.Title;
model.Description = blog.Description;
model.Posts = (foundPosts != null && foundPosts.Any()) ? foundPosts.ToList() : null;
model.HasPosts = (foundPosts != null && foundPosts.Any());
return View(model);
}

2
Teknik/Areas/Blog/ViewModels/BlogViewModel.cs

@ -20,6 +20,6 @@ namespace Teknik.Areas.Blog.ViewModels @@ -20,6 +20,6 @@ namespace Teknik.Areas.Blog.ViewModels
public User User { get; set; }
public List<Post> Posts { get; set; }
public bool HasPosts { get; set; }
}
}

7
Teknik/Areas/Blog/Views/Blog/Blog.cshtml

@ -28,8 +28,6 @@ @@ -28,8 +28,6 @@
<div class="container">
@if (Model != null && Model.User != null)
{
if (Model.BlogId != Constants.SERVERBLOGID)
{
<div class="row">
<div class="col-sm-12 blog-heading">
<h1 class="blog-title text-center">@Model.Title</h1>
@ -39,11 +37,10 @@ @@ -39,11 +37,10 @@
<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>
<a href="@Url.Action("Blog", "RSS", new { area = "RSS", username = (Model.BlogId == Constants.SERVERBLOGID) ? string.Empty : 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">
@ -115,7 +112,7 @@ @@ -115,7 +112,7 @@
</div>
}
if (Model.Posts != null && Model.Posts.Any())
if (Model.HasPosts)
{
<div class="blog-main" id="@Model.BlogId"></div>
<script>

2
Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml

@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
}
<ol class="breadcrumb">
<li><a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = Model.Blog.User.Username })">@Model.Blog.User.Username</a></li>
<li><a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = (Model.BlogId == Constants.SERVERBLOGID) ? string.Empty : Model.Blog.User.Username })">@((Model.BlogId == Constants.SERVERBLOGID) ? ViewBag.Config.BlogTitle : Model.Blog.Title)</a></li>
<li class="active"><a href="#">@Model.Title</a></li>
</ol>

2
Teknik/Areas/Home/Controllers/HomeController.cs

@ -27,7 +27,7 @@ namespace Teknik.Areas.Home.Controllers @@ -27,7 +27,7 @@ namespace Teknik.Areas.Home.Controllers
lastSite = foundSite.ToList();
// Grab the latest user blog posts
List<Post> lastPosts = new List<Post>();
var foundPosts = db.Posts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published).Take(10);
var foundPosts = db.Posts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published && p.BlogId != Constants.SERVERBLOGID).Take(10);
if (foundPosts != null)
lastPosts = foundPosts.ToList();
// Grab the latest podcasts

13
Teknik/Configuration/Config.cs

@ -20,25 +20,32 @@ namespace Teknik @@ -20,25 +20,32 @@ namespace Teknik
private SMTPConfig _SMTPConfig;
private string _SupportEmail;
private string _BitcoinAddress;
private string _BlogTitle;
private string _BlogDescription;
private int _PostsToLoad;
private int _CommentsToLoad;
public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
// Site Information
public string Title { get { return _Title; } set { _Title = value; } }
public string Description { get { return _Description; } set { _Description = value; } }
public string Author { get { return _Author; } set { _Author = value; } }
public string Host { get { return _Host; } set { _Host = value; } }
// Mail Server Information
public SMTPConfig SMTPConfig { get { return _SMTPConfig; } set { _SMTPConfig = value; } }
// Contact Information
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
// About Information
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
// Blog Information
public string BlogTitle { get { return _BlogTitle; } set { _BlogTitle = value; } }
public string BlogDescription { get { return _BlogDescription; } set { _BlogDescription = value; } }
public int PostsToLoad { get { return _PostsToLoad; } set { _PostsToLoad = value; } }
public int CommentsToLoad { get { return _CommentsToLoad; } set { _CommentsToLoad = value; } }
public Config()
@ -61,6 +68,8 @@ namespace Teknik @@ -61,6 +68,8 @@ namespace Teknik
SMTPConfig = new SMTPConfig();
SupportEmail = string.Empty;
BitcoinAddress = string.Empty;
BlogTitle = string.Empty;
BlogDescription = string.Empty;
PostsToLoad = 10;
CommentsToLoad = 10;
}

2
Teknik/Helpers/Constants.cs

@ -9,6 +9,6 @@ namespace Teknik.Helpers @@ -9,6 +9,6 @@ namespace Teknik.Helpers
public static class Constants
{
// Blog Constants
public static int SERVERBLOGID = 0;
public static int SERVERBLOGID = 1;
}
}

1
Teknik/Views/Shared/_Layout.cshtml

@ -9,7 +9,6 @@ @@ -9,7 +9,6 @@
<title>@ViewBag.Title</title>
<link rel="shortcut icon" href="/Images/favicon.ico" type="image/x-icon" />
@Styles.Render("~/Content/Common")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/markdown")

4
Teknik/Web.config

@ -50,6 +50,10 @@ @@ -50,6 +50,10 @@
</rule>
</rules>
</rewrite>-->
<staticContent>
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Loading…
Cancel
Save