2023-08-11 15:51:20 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-08-06 15:57:23 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
using OliverBooth.Data.Blog;
|
2023-08-08 02:06:11 +01:00
|
|
|
using OliverBooth.Services;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-11 14:08:14 +01:00
|
|
|
namespace OliverBooth.Areas.Blog.Pages;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-08 02:06:11 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Represents the page model for the <c>Article</c> page.
|
|
|
|
/// </summary>
|
2023-08-11 14:26:21 +01:00
|
|
|
[Area("blog")]
|
2023-08-06 15:57:23 +01:00
|
|
|
public class Article : PageModel
|
|
|
|
{
|
2023-08-08 02:06:11 +01:00
|
|
|
private readonly BlogService _blogService;
|
2023-08-12 14:24:27 +01:00
|
|
|
private readonly BlogUserService _blogUserService;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-08 02:06:11 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="Article" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="blogService">The <see cref="BlogService" />.</param>
|
2023-08-12 14:24:27 +01:00
|
|
|
/// <param name="blogUserService">The <see cref="BlogUserService" />.</param>
|
|
|
|
public Article(BlogService blogService, BlogUserService blogUserService)
|
2023-08-06 15:57:23 +01:00
|
|
|
{
|
2023-08-08 02:06:11 +01:00
|
|
|
_blogService = blogService;
|
2023-08-12 14:24:27 +01:00
|
|
|
_blogUserService = blogUserService;
|
2023-08-06 15:57:23 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 02:06:11 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the author of the post.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The author of the post.</value>
|
2023-08-12 14:24:27 +01:00
|
|
|
public User Author { get; private set; } = null!;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-08 01:17:23 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether the post is a legacy WordPress post.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// <see langword="true" /> if the post is a legacy WordPress post; otherwise, <see langword="false" />.
|
|
|
|
/// </value>
|
2023-08-08 02:06:11 +01:00
|
|
|
public bool IsWordPressLegacyPost => Post.WordPressId.HasValue;
|
2023-08-08 01:17:23 +01:00
|
|
|
|
2023-08-08 02:06:11 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the requested blog post.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The requested blog post.</value>
|
|
|
|
public BlogPost Post { get; private set; } = null!;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-08 00:28:33 +01:00
|
|
|
public IActionResult OnGet(int year, int month, int day, string slug)
|
2023-08-06 15:57:23 +01:00
|
|
|
{
|
2023-08-08 02:06:11 +01:00
|
|
|
if (!_blogService.TryGetBlogPost(year, month, day, slug, out BlogPost? post))
|
2023-08-06 15:57:23 +01:00
|
|
|
{
|
|
|
|
Response.StatusCode = 404;
|
2023-08-08 00:28:33 +01:00
|
|
|
return NotFound();
|
2023-08-06 15:57:23 +01:00
|
|
|
}
|
2023-08-08 00:28:33 +01:00
|
|
|
|
2023-08-08 02:06:11 +01:00
|
|
|
Post = post;
|
2023-08-12 14:24:27 +01:00
|
|
|
Author = _blogUserService.TryGetUser(post.AuthorId, out User? author) ? author : null!;
|
2023-08-08 00:28:33 +01:00
|
|
|
return Page();
|
2023-08-06 15:57:23 +01:00
|
|
|
}
|
|
|
|
}
|