Get latest post and display on homepage

This commit is contained in:
Robert Marshall 2019-04-27 21:39:22 +01:00
parent 9e35d0ab90
commit 15b01412f2
3 changed files with 36 additions and 4 deletions

View file

@ -4,15 +4,24 @@ using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Website.Data;
using Website.ViewModels;
namespace Website.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
private readonly BlogRepository _blogRepo;
public HomeController(BlogRepository blogRepo)
{
return View();
_blogRepo = blogRepo;
}
public async Task<IActionResult> Index()
{
var post = await _blogRepo.GetLatestPostAsync();
return View(post);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]