View blog posts
This commit is contained in:
parent
b8f371e3e8
commit
3064dd8d25
5 changed files with 16 additions and 13 deletions
|
@ -28,9 +28,9 @@ namespace Website.Controllers
|
|||
return View(model);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> View(int id)
|
||||
public async Task<IActionResult> Entry(string url)
|
||||
{
|
||||
var post = await _repo.GetPostAsync(id);
|
||||
var post = await _repo.GetPostByUrlAsync(url);
|
||||
var model = new BlogPostViewModel(post);
|
||||
return View(model);
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ namespace Website.Data
|
|||
|
||||
public BlogRepository(IDatabaseProvider dbProvider) => _dbProvider = dbProvider;
|
||||
|
||||
public async Task<BlogPost> GetPostAsync(int id) {
|
||||
const string query = "SELECT * FROM blog_posts WHERE post_id=@id AND post_deleted=0";
|
||||
public async Task<BlogPost> 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<BlogPostState>(query, new{id});
|
||||
var result = await connection.QueryAsync<BlogPostState>(query, new{url});
|
||||
return new BlogPost(result.First());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?}");
|
||||
|
|
9
Website/Views/Blog/Entry.cshtml
Normal file
9
Website/Views/Blog/Entry.cshtml
Normal file
|
@ -0,0 +1,9 @@
|
|||
@model BlogPostViewModel;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = Model.Title;
|
||||
}
|
||||
|
||||
@Html.Raw(Model.Content)
|
||||
|
||||
<small>Posted on @Model.Timestamp.ToString()</small>
|
|
@ -1,7 +0,0 @@
|
|||
@model BlogPostViewModel;
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Blog";
|
||||
}
|
||||
|
||||
@Model.Title
|
Loading…
Add table
Add a link
Reference in a new issue