using JoshHeaps.Net.Models; using JoshHeaps.Net.Services.Implementations; using JoshHeaps.Net.Services.Interfaces; using Microsoft.AspNetCore.Mvc; namespace JoshHeaps.Net.Pages.Socialism; public class DocModel(ISocialismDocService docService) : SocialismPageModel { public SocialismDoc? Doc { get; private set; } public SocialismDoc? Previous { get; private set; } public SocialismDoc? Next { get; private set; } public IActionResult OnGet(string slug) { if (slug == SocialismDocService.IndexSlug) return RedirectPermanent("/socialism"); Doc = docService.GetDoc(slug); if (Doc is null) return NotFound(); CurrentSlug = slug; AllDocs = docService.GetAllDocs(); var position = AllDocs.FindIndex(d => d.Slug == slug); Previous = position > 0 ? AllDocs[position - 1] : null; Next = position >= 0 && position < AllDocs.Count - 1 ? AllDocs[position + 1] : null; return Page(); } }