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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. namespace Teknik.Areas.Home.Controllers
  13. {
  14. public class HomeController : DefaultController
  15. {
  16. // GET: Home/Home
  17. private TeknikEntities db = new TeknikEntities();
  18. [AllowAnonymous]
  19. public ActionResult Index()
  20. {
  21. HomeViewModel model = new HomeViewModel();
  22. // Grab the latest site blog posts
  23. List<BlogPost> lastSite = new List<BlogPost>();
  24. var foundSite = db.BlogPosts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published && p.System).Take(10);
  25. if (foundSite != null)
  26. lastSite = foundSite.ToList();
  27. // Grab the latest user blog posts
  28. List<BlogPost> lastPosts = new List<BlogPost>();
  29. var foundPosts = db.BlogPosts.Include("Blog").Include("Blog.User").OrderBy(post => post.DatePosted).Where(p => p.Published && !p.System).Take(10);
  30. if (foundPosts != null)
  31. lastPosts = foundPosts.ToList();
  32. // Grab the latest podcasts
  33. List<Podcast.Models.Podcast> lastPods = new List<Podcast.Models.Podcast>();
  34. var foundPods = db.Podcasts.OrderBy(post => post.DatePosted).Where(p => p.Published).Take(10);
  35. if (foundPods != null)
  36. lastPods = foundPods.ToList();
  37. model.SitePosts = lastSite;
  38. model.Podcasts = lastPods;
  39. model.BlogPosts = lastPosts;
  40. ViewBag.Title = Config.Title;
  41. return View(model);
  42. }
  43. }
  44. }