diff --git a/Website/Controllers/BlogController.cs b/Website/Controllers/BlogController.cs index 444eb93..610e73c 100644 --- a/Website/Controllers/BlogController.cs +++ b/Website/Controllers/BlogController.cs @@ -28,9 +28,9 @@ namespace Website.Controllers return View(model); } - public async Task View(int id) + public async Task Entry(string url) { - var post = await _repo.GetPostAsync(id); + var post = await _repo.GetPostByUrlAsync(url); var model = new BlogPostViewModel(post); return View(model); } diff --git a/Website/Data/BlogRepository.cs b/Website/Data/BlogRepository.cs index 00515c3..8472959 100644 --- a/Website/Data/BlogRepository.cs +++ b/Website/Data/BlogRepository.cs @@ -13,11 +13,11 @@ namespace Website.Data public BlogRepository(IDatabaseProvider dbProvider) => _dbProvider = dbProvider; - public async Task GetPostAsync(int id) { - const string query = "SELECT * FROM blog_posts WHERE post_id=@id AND post_deleted=0"; + public async Task GetPostByUrlAsync(string url) { + const string query = "SELECT * FROM blog_posts WHERE post_url=@url AND post_deleted=0"; using (var connection = _dbProvider.NewConnection()) { connection.Open(); - var result = await connection.QueryAsync(query, new{id}); + var result = await connection.QueryAsync(query, new{url}); return new BlogPost(result.First()); } } diff --git a/Website/Startup.cs b/Website/Startup.cs index 4a66dfc..79d7a9b 100644 --- a/Website/Startup.cs +++ b/Website/Startup.cs @@ -63,7 +63,8 @@ namespace Website new { controller = "Blog", action = "Page", page = 1 }); routes.MapRoute( name: "blogView", - template: "blog/view/{url}"); + template: "blog/view/{url}", + new { controller = "Blog", action = "Entry"}); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); diff --git a/Website/Views/Blog/Entry.cshtml b/Website/Views/Blog/Entry.cshtml new file mode 100644 index 0000000..4812180 --- /dev/null +++ b/Website/Views/Blog/Entry.cshtml @@ -0,0 +1,9 @@ +@model BlogPostViewModel; + +@{ + ViewData["Title"] = Model.Title; +} + +@Html.Raw(Model.Content) + +Posted on @Model.Timestamp.ToString() \ No newline at end of file diff --git a/Website/Views/Blog/View.cshtml b/Website/Views/Blog/View.cshtml deleted file mode 100644 index 9cc8478..0000000 --- a/Website/Views/Blog/View.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@model BlogPostViewModel; - -@{ - ViewData["Title"] = "Blog"; -} - -@Model.Title \ No newline at end of file