using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OliverBooth.Data.Blog;
using OliverBooth.Services;
namespace OliverBooth.Pages.Blog;
///
/// Represents the page model for the Article page.
///
public class Article : PageModel
{
private readonly BlogService _blogService;
///
/// Initializes a new instance of the class.
///
/// The .
public Article(BlogService blogService)
{
_blogService = blogService;
}
///
/// Gets the author of the post.
///
/// The author of the post.
public Author Author { get; private set; } = null!;
///
/// Gets a value indicating whether the post is a legacy WordPress post.
///
///
/// if the post is a legacy WordPress post; otherwise, .
///
public bool IsWordPressLegacyPost => Post.WordPressId.HasValue;
///
/// Gets the requested blog post.
///
/// The requested blog post.
public BlogPost Post { get; private set; } = null!;
public IActionResult OnGet(int year, int month, int day, string slug)
{
if (!_blogService.TryGetBlogPost(year, month, day, slug, out BlogPost? post))
{
Response.StatusCode = 404;
return NotFound();
}
Post = post;
Author = _blogService.TryGetAuthor(post, out Author? author) ? author : null!;
return Page();
}
}