using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using OliverBooth.Blog.Data; using OliverBooth.Blog.Services; namespace OliverBooth.Blog.Pages; /// /// Represents the page model for the Article page. /// [Area("blog")] public class Article : PageModel { private readonly IBlogPostService _blogPostService; /// /// Initializes a new instance of the class. /// /// The . public Article(IBlogPostService blogPostService) { _blogPostService = blogPostService; } /* /// /// 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 IBlogPost Post { get; private set; } = null!; public IActionResult OnGet(int year, int month, int day, string slug) { var date = new DateOnly(year, month, day); if (!_blogPostService.TryGetPost(date, slug, out IBlogPost? post)) { Response.StatusCode = 404; return NotFound(); } if (post.IsRedirect) { return Redirect(post.RedirectUrl!.ToString()); } Post = post; return Page(); } }