The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HomeController.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Podcast.Models;
  7. using Teknik.Areas.Blog.Models;
  8. using Teknik.Areas.Home.ViewModels;
  9. using Teknik.Controllers;
  10. using Teknik.Helpers;
  11. using Teknik.Models;
  12. using Teknik.Filters;
  13. namespace Teknik.Areas.Home.Controllers
  14. {
  15. public class HomeController : DefaultController
  16. {
  17. // GET: Home/Home
  18. private TeknikEntities db = new TeknikEntities();
  19. [TrackPageView]
  20. [AllowAnonymous]
  21. public ActionResult Index()
  22. {
  23. HomeViewModel model = new HomeViewModel();
  24. // Grab the latest site blog posts
  25. List<BlogPost> lastSite = new List<BlogPost>();
  26. if (db.BlogPosts.Count() > 0)
  27. {
  28. var foundSite = db.BlogPosts.Include("Blog").Include("Blog.User").OrderByDescending(post => post.DatePosted).Where(p => p.Published && p.System).Take(5);
  29. if (foundSite != null)
  30. lastSite = foundSite.ToList();
  31. }
  32. // Grab the latest user blog posts
  33. List<BlogPost> lastPosts = new List<BlogPost>();
  34. if (db.BlogPosts.Count() > 0)
  35. {
  36. var foundPosts = db.BlogPosts.Include("Blog").Include("Blog.User").OrderByDescending(post => post.DatePosted).Where(p => p.Published && !p.System).Take(5);
  37. if (foundPosts != null)
  38. lastPosts = foundPosts.ToList();
  39. }
  40. // Grab the latest podcasts
  41. List<Podcast.Models.Podcast> lastPods = new List<Podcast.Models.Podcast>();
  42. if (db.Podcasts.Count() > 0)
  43. {
  44. var foundPods = db.Podcasts.OrderByDescending(post => post.DatePosted).Where(p => p.Published).Take(5);
  45. if (foundPods != null)
  46. lastPods = foundPods.ToList();
  47. }
  48. model.SitePosts = lastSite;
  49. model.Podcasts = lastPods;
  50. model.BlogPosts = lastPosts;
  51. ViewBag.Title = Config.Title;
  52. return View(model);
  53. }
  54. }
  55. }