oliverbooth.dev/OliverBooth/Pages/Tutorials/Index.cshtml.cs
Oliver Booth 6ec4103a3a
refactor: separate Markdig extensions from project
Also introduces .Common project to house common references and types
2024-05-05 02:18:20 +01:00

37 lines
981 B
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OliverBooth.Common.Data.Web;
using OliverBooth.Common.Services;
namespace OliverBooth.Pages.Tutorials;
public class Index : PageModel
{
private readonly ITutorialService _tutorialService;
/// <summary>
/// Initializes a new instance of the <see cref="Index" /> class.
/// </summary>
/// <param name="tutorialService">The tutorial service.</param>
public Index(ITutorialService tutorialService)
{
_tutorialService = tutorialService;
}
public ITutorialFolder? CurrentFolder { get; private set; }
public void OnGet([FromRoute(Name = "slug")] string? slug)
{
if (slug is null) return;
string[] tokens = slug.Split('/');
ITutorialFolder? folder = null;
foreach (string token in tokens)
{
folder = _tutorialService.GetFolder(token, folder);
}
CurrentFolder = folder;
}
}