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

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