Browse Source

Added viewmodel and news/podcast displaying to home view

tags/2.0.3
Teknikode 5 years ago
parent
commit
702ee98600

+ 19
- 4
Teknik/Areas/Home/Controllers/HomeController.cs View File

@@ -4,7 +4,9 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using Teknik.Areas.Blog.Models;
using Teknik.Areas.Home.ViewModels;
using Teknik.Controllers;
using Teknik.Helpers;
using Teknik.Models;

namespace Teknik.Areas.Home.Controllers
@@ -17,13 +19,26 @@ namespace Teknik.Areas.Home.Controllers
[AllowAnonymous]
public ActionResult Index()
{
HomeViewModel model = new HomeViewModel();
// Grab the latest site blog posts
List<Post> lastSite = new List<Post>();
var foundSite = db.Posts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published && p.BlogId == Constants.SERVERBLOGID).Take(10);
if (foundSite != null)
lastSite = foundSite.ToList();
// Grab the latest user blog posts
List<Post> lastPosts = new List<Post>();
var found = db.Posts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published).Take(10);
if (found != null)
lastPosts = found.ToList();
var foundPosts = db.Posts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published).Take(10);
if (foundPosts != null)
lastPosts = foundPosts.ToList();
// Grab the latest podcasts
List<Post> lastPods = new List<Post>();

model.SitePosts = lastSite;
model.Podcasts = lastPods;
model.BlogPosts = lastPods;

ViewBag.Title = Config.Title;
return View(lastPosts);
return View(model);
}
}
}

+ 16
- 0
Teknik/Areas/Home/ViewModels/HomeViewModel.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teknik.Areas.Blog.Models;

namespace Teknik.Areas.Home.ViewModels
{
public class HomeViewModel
{
public List<Post> SitePosts { get; set; }
public List<Post> Podcasts { get; set; }
public List<Post> BlogPosts { get; set; }
}
}

+ 136
- 17
Teknik/Areas/Home/Views/Home/Index.cshtml View File

@@ -1,4 +1,7 @@
@using Teknik.Areas.Blog.Models
@model Teknik.Areas.Home.ViewModels.HomeViewModel

@using Teknik.Areas.Blog.Models

<div class="container">
<div class="row">
<center>
@@ -116,34 +119,150 @@
</div>

<div class="container">
<!-- Display Site News -->
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center">Recent Blog Posts</h3>
<h3 class="panel-title text-center">Recent News</h3>
</div>
<div class="panel-body">
<p>
<ul class="list-group">
@foreach (Post post in Model)
@if (Model.SitePosts.Any())
{
foreach (Post post in Model.SitePosts)
{
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@post.PostId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@post.PostId").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left">
<a href="@Url.Action("Post", "Blog", new { area = "Blog", username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
</h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on @post.DatePosted.ToString("MMMM dd, yyyy") by <a href="@Url.Action("Index", "Profile", new { area = "Profile", username = post.Blog.User.Username })">@post.Blog.User.Username</a>
</p>
</div>
</div>
</div>
</li>
}
}
else
{
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@post.PostId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@post.PostId").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="@Url.Action("Post", "Blog", new { area = "Blog", username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
</h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on @post.DatePosted.ToString("MMMM dd, yyyy") by <a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = post.Blog.User.Username })">@post.Blog.User.Username</a>
</p>
<div class="col-sm-12 text-center">
<h2>No News Available</h2>
</div>
</div>
</li>
}
</ul>
</p>
</div>
</div>
</div>
<!-- Display Recent Podcasts -->
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center">Recent Podcasts</h3>
</div>
<div class="panel-body">
<p>
<ul class="list-group">
@if (Model.Podcasts.Any())
{
foreach (Post post in Model.Podcasts)
{
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@post.PostId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@post.PostId").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left">
<a href="@Url.Action("Post", "Blog", new { area = "Blog", username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
</h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on @post.DatePosted.ToString("MMMM dd, yyyy")
</p>
</div>
</div>
</div>
</li>
}
}
else
{
<li class="list-group-item">
<div class="row">
<div class="col-sm-12 text-center">
<h2>No Podcasts Available</h2>
</div>
</div>
</li>
}
</ul>
</p>
</div>
</div>
</div>
<!-- Display Recent Blog Posts -->
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center">Recent Blog Posts</h3>
</div>
<div class="panel-body">
<p>
<ul class="list-group">
@if (Model.BlogPosts.Any())
{
foreach (Post post in Model.BlogPosts)
{
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@post.PostId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@post.PostId").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="@Url.Action("Post", "Blog", new { area = "Blog", username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
</h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on @post.DatePosted.ToString("MMMM dd, yyyy") by <a href="@Url.Action("Index", "Profile", new { area = "Profile", username = post.Blog.User.Username })">@post.Blog.User.Username</a>
</p>
</div>
</div>
</div>
</li>
}
}
else
{
<li class="list-group-item">
<div class="row">
<div class="col-sm-12 text-center">
<h2>No Posts Available</h2>
</div>
</div>
</li>
}

+ 1
- 0
Teknik/Teknik.csproj View File

@@ -151,6 +151,7 @@
<Compile Include="Areas\Dev\DevAreaRegistration.cs" />
<Compile Include="Areas\Home\Controllers\HomeController.cs" />
<Compile Include="Areas\Home\HomeAreaRegistration.cs" />
<Compile Include="Areas\Home\ViewModels\HomeViewModel.cs" />
<Compile Include="Areas\Privacy\Controllers\PrivacyController.cs" />
<Compile Include="Areas\Privacy\PrivacyAreaRegistration.cs" />
<Compile Include="Areas\Profile\Controllers\ProfileController.cs" />

Loading…
Cancel
Save