oliverbooth.dev/OliverBooth.Blog/Pages/Article.cshtml.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2023-08-11 14:51:20 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OliverBooth.Blog.Data;
using OliverBooth.Blog.Services;
namespace OliverBooth.Blog.Pages;
/// <summary>
/// Represents the page model for the <c>Article</c> page.
/// </summary>
[Area("blog")]
public class Article : PageModel
{
private readonly IBlogPostService _blogPostService;
/// <summary>
/// Initializes a new instance of the <see cref="Article" /> class.
/// </summary>
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
public Article(IBlogPostService blogPostService)
{
_blogPostService = blogPostService;
}
/*
2023-08-08 00:17:23 +00: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>
public bool IsWordPressLegacyPost => Post.WordPressId.HasValue;
*/
2023-08-08 00:17:23 +00:00
/// <summary>
/// Gets the requested blog post.
/// </summary>
/// <value>The requested blog post.</value>
public IBlogPost Post { get; private set; } = null!;
2023-08-07 23:28:33 +00:00
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;
2023-08-07 23:28:33 +00:00
return NotFound();
}
2023-08-07 23:28:33 +00:00
if (post.IsRedirect)
{
return Redirect(post.RedirectUrl!.ToString());
}
Post = post;
2023-08-07 23:28:33 +00:00
return Page();
}
}