Files
2026-02-23 13:05:16 -05:00

82 lines
2.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using maintenance.Services.Templates;
namespace maintenance.Pages.Errors;
public sealed class TemplateModel : PageModel
{
private readonly ITemplateService _templateService;
public TemplateModel(ITemplateService templateService)
{
_templateService = templateService;
}
[FromQuery(Name = "template")]
public string TemplateName { get; set; } = "template";
[FromQuery(Name = "errorName")]
public string ErrorName { get; set; } = "Error Name";
[FromQuery(Name = "short")]
public string? ShortDescription { get; set; }
[FromQuery(Name = "desc")]
public string Description { get; set; } = "An error has occurred. Please contact MAX Support for assistance.";
[FromQuery(Name = "instructionsHeader")]
public string? InstructionsHeader { get; set; }
[FromQuery(Name = "steps")]
public string? StepsCsv { get; set; }
[FromQuery(Name = "showSupport")]
public bool ShowSupport { get; set; } = true;
[FromQuery(Name = "showInstructions")]
public bool ShowInstructions { get; set; } = true;
[FromQuery(Name = "code")]
public string ErrorCode { get; set; } = "eaX";
public string? SupportContactBlock { get; private set; }
public IReadOnlyList<string> InstructionSteps { get; private set; } = new List<string>
{
"Change some setting"
};
public async Task OnGetAsync()
{
var template = await _templateService.GetByNameAsync(TemplateName, HttpContext.RequestAborted);
if (template is not null)
{
if (!Request.Query.ContainsKey("errorName") && !string.IsNullOrWhiteSpace(template.Title))
{
ErrorName = template.Title;
}
if (!Request.Query.ContainsKey("desc") && !string.IsNullOrWhiteSpace(template.Body))
{
Description = template.Body;
}
SupportContactBlock = template.SupportContactBlock;
if (!Request.Query.ContainsKey("showSupport") && string.IsNullOrWhiteSpace(SupportContactBlock))
{
ShowSupport = false;
}
}
if (!string.IsNullOrWhiteSpace(StepsCsv))
{
InstructionSteps = StepsCsv
.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();
}
}
}