mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed server specific blog viewing (Set to be first blog in DB)
This commit is contained in:
parent
34836c9a08
commit
a4a11d7076
@ -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);
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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 @@
|
||||
<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 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
if (Model.Posts != null && Model.Posts.Any())
|
||||
if (Model.HasPosts)
|
||||
{
|
||||
<div class="blog-main" id="@Model.BlogId"></div>
|
||||
<script>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
SMTPConfig = new SMTPConfig();
|
||||
SupportEmail = string.Empty;
|
||||
BitcoinAddress = string.Empty;
|
||||
BlogTitle = string.Empty;
|
||||
BlogDescription = string.Empty;
|
||||
PostsToLoad = 10;
|
||||
CommentsToLoad = 10;
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ namespace Teknik.Helpers
|
||||
public static class Constants
|
||||
{
|
||||
// Blog Constants
|
||||
public static int SERVERBLOGID = 0;
|
||||
public static int SERVERBLOGID = 1;
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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…
Reference in New Issue
Block a user