The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

HomeController.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Teknik.Areas.Blog.Models;
  4. using Teknik.Areas.Home.ViewModels;
  5. using Teknik.Controllers;
  6. using Teknik.Filters;
  7. using Teknik.Attributes;
  8. using Microsoft.Extensions.Logging;
  9. using Teknik.Configuration;
  10. using Teknik.Data;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.EntityFrameworkCore;
  14. using Teknik.Logging;
  15. using System;
  16. namespace Teknik.Areas.Home.Controllers
  17. {
  18. [Authorize]
  19. [Area("Home")]
  20. public class HomeController : DefaultController
  21. {
  22. public HomeController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
  23. [AllowAnonymous]
  24. public IActionResult Index()
  25. {
  26. HomeViewModel model = new HomeViewModel();
  27. // Grab the latest site blog posts
  28. List<BlogPost> lastSite = new List<BlogPost>();
  29. var foundSite = _dbContext.BlogPosts.Include(p => p.Blog).Include(b => b.Blog.User).OrderByDescending(post => post.DatePosted).Where(p => p.Published && p.System).Take(5);
  30. if (foundSite != null)
  31. lastSite = foundSite.ToList();
  32. // Grab the latest podcasts
  33. List<Podcast.Models.Podcast> lastPods = new List<Podcast.Models.Podcast>();
  34. var foundPods = _dbContext.Podcasts.OrderByDescending(post => post.DatePosted).Where(p => p.Published).Take(5);
  35. if (foundPods != null)
  36. lastPods = foundPods.ToList();
  37. model.SitePosts = lastSite;
  38. model.Podcasts = lastPods;
  39. return View(model);
  40. }
  41. }
  42. }