website/Website/Controllers/HomeController.cs

33 lines
805 B
C#

using System;
using System.Collections.Generic;
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
{
private readonly BlogRepository _blogRepo;
public HomeController(BlogRepository blogRepo)
{
_blogRepo = blogRepo;
}
public async Task<IActionResult> Index()
{
var post = await _blogRepo.GetLatestPostAsync();
return View(post);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}