diff --git a/Teknik/Areas/Home/Controllers/HomeController.cs b/Teknik/Areas/Home/Controllers/HomeController.cs index 555b9af..600cee8 100644 --- a/Teknik/Areas/Home/Controllers/HomeController.cs +++ b/Teknik/Areas/Home/Controllers/HomeController.cs @@ -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 lastSite = new List(); + 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 lastPosts = new List(); - 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 lastPods = new List(); + + model.SitePosts = lastSite; + model.Podcasts = lastPods; + model.BlogPosts = lastPods; ViewBag.Title = Config.Title; - return View(lastPosts); + return View(model); } } } \ No newline at end of file diff --git a/Teknik/Areas/Home/ViewModels/HomeViewModel.cs b/Teknik/Areas/Home/ViewModels/HomeViewModel.cs new file mode 100644 index 0000000..6281bee --- /dev/null +++ b/Teknik/Areas/Home/ViewModels/HomeViewModel.cs @@ -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 SitePosts { get; set; } + public List Podcasts { get; set; } + public List BlogPosts { get; set; } + } +} diff --git a/Teknik/Areas/Home/Views/Home/Index.cshtml b/Teknik/Areas/Home/Views/Home/Index.cshtml index 02c2e9b..8c196ae 100644 --- a/Teknik/Areas/Home/Views/Home/Index.cshtml +++ b/Teknik/Areas/Home/Views/Home/Index.cshtml @@ -1,4 +1,7 @@ -@using Teknik.Areas.Blog.Models +@model Teknik.Areas.Home.ViewModels.HomeViewModel + +@using Teknik.Areas.Blog.Models +
@@ -116,6 +119,109 @@
+ +
+
+
+

Recent News

+
+
+

+

    + @if (Model.SitePosts.Any()) + { + foreach (Post post in Model.SitePosts) + { + +
  • +
    +
    +
    +

    + @post.Title +

    + +
    +
    +
    +
  • + } + } + else + { +
  • +
    +
    +

    No News Available

    +
    +
    +
  • + } +
+

+
+
+
+ +
+
+
+

Recent Podcasts

+
+
+

+

    + @if (Model.Podcasts.Any()) + { + foreach (Post post in Model.Podcasts) + { + +
  • +
    +
    +
    +

    + @post.Title +

    + +
    +
    +
    +
  • + } + } + else + { +
  • +
    +
    +

    No Podcasts Available

    +
    +
    +
  • + } +
+

+
+
+
+
@@ -124,25 +230,38 @@

    - @foreach (Post post in Model) + @if (Model.BlogPosts.Any()) + { + foreach (Post post in Model.BlogPosts) + { + +
  • +
    +
    +
    +

    @post.Title +

    + +
    +
    +
    +
  • + } + } + else { -
  • -
    -
    -

    @post.Title -

    - -
    +
    +

    No Posts Available

  • diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index c953a31..026d3ad 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -151,6 +151,7 @@ +