diff --git a/Website/Controllers/HomeController.cs b/Website/Controllers/HomeController.cs index 4b7c9cc..0e46dab 100644 --- a/Website/Controllers/HomeController.cs +++ b/Website/Controllers/HomeController.cs @@ -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 Index() + { + var post = await _blogRepo.GetLatestPostAsync(); + return View(post); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/Website/Data/BlogRepository.cs b/Website/Data/BlogRepository.cs index 8cb7e0d..6a0aacc 100644 --- a/Website/Data/BlogRepository.cs +++ b/Website/Data/BlogRepository.cs @@ -20,5 +20,14 @@ namespace Website.Data return new BlogPost(result.First()); } } + + public async Task GetLatestPostAsync() { + const string query = "SELECT * FROM blog_posts WHERE post_content<>'' AND post_deleted=0 ORDER BY post_timestamp DESC LIMIT 1"; + using (var connection = _dbProvider.NewConnection()) { + connection.Open(); + var result = await connection.QueryAsync(query); + return new BlogPost(result.First()); + } + } } } \ No newline at end of file diff --git a/Website/Views/Home/Index.cshtml b/Website/Views/Home/Index.cshtml index 89aef55..fe03240 100644 --- a/Website/Views/Home/Index.cshtml +++ b/Website/Views/Home/Index.cshtml @@ -1,6 +1,20 @@ -@{ +@using Website.Models; +@model BlogPost; + +@{ ViewData["Title"] = "Home"; } +@section CSS{ + h3 a { + color:inherit; + } +}

Hi, I'm Rob. I'm a senior software engineer at Code Computerlove.

-

If you wish to get in contact, then get in touch via my LinkedIn profile

\ No newline at end of file +

If you wish to get in contact, then get in touch via my LinkedIn profile

+
+

Latest Blog Post

+

@Model.Title

+@Model.Content +Posted on @Model.Timestamp.ToString() +

Read more...

\ No newline at end of file