diff --git a/Pages/Errors/Generic.cshtml b/Pages/Errors/Generic.cshtml index faccd29..a2140e9 100644 --- a/Pages/Errors/Generic.cshtml +++ b/Pages/Errors/Generic.cshtml @@ -8,29 +8,36 @@ - MAX - System Error + MAX - @Model.Title
MAX
-

System Error

+

@Model.Title

-

A system error has occurred. Please contact MAX Support.

+

@Model.Description

-

MAX Support:

-
-

Email: maxsupport@max.gov

-

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

-
-

Phone: 202-395-6860

-

Available 8:00AM - 6:30PM Weekdays

-
-

All hours in Eastern Time (ET)

+ @if (!string.IsNullOrWhiteSpace(Model.SupportContactBlock)) + { + @Html.Raw(Model.SupportContactBlock) + } + else + { +

MAX Support:

+
+

Email: maxsupport@max.gov

+

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

+
+

Phone: 202-395-6860

+

Available 8:00AM - 6:30PM Weekdays

+
+

All hours in Eastern Time (ET)

+ }
-

(Error Code: eag)

+

(Error Code: @Model.ErrorCode)

diff --git a/Pages/Errors/Generic.cshtml.cs b/Pages/Errors/Generic.cshtml.cs index eae36e8..d23aee3 100644 --- a/Pages/Errors/Generic.cshtml.cs +++ b/Pages/Errors/Generic.cshtml.cs @@ -1,10 +1,32 @@ using Microsoft.AspNetCore.Mvc.RazorPages; +using maintenance.Services.Templates; namespace maintenance.Pages.Errors; public sealed class GenericModel : PageModel { - public void OnGet() + private readonly ITemplateService _templateService; + + public GenericModel(ITemplateService templateService) { + _templateService = templateService; + } + + public string Title { get; private set; } = "System Error"; + public string Description { get; private set; } = "A system error has occurred. Please contact MAX Support."; + public string ErrorCode { get; private set; } = "eag"; + public string? SupportContactBlock { get; private set; } + + public async Task OnGetAsync() + { + var template = await _templateService.GetByNameAsync("generic", HttpContext.RequestAborted); + if (template is null) + { + return; + } + + Title = string.IsNullOrWhiteSpace(template.Title) ? Title : template.Title; + Description = string.IsNullOrWhiteSpace(template.Body) ? Description : template.Body; + SupportContactBlock = template.SupportContactBlock; } } diff --git a/Pages/Errors/Template.cshtml b/Pages/Errors/Template.cshtml index dd624e9..db41574 100644 --- a/Pages/Errors/Template.cshtml +++ b/Pages/Errors/Template.cshtml @@ -47,15 +47,22 @@ @if (Model.ShowSupport) {
-

MAX Support:

-
-

Email: maxsupport@max.gov

-

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

-
-

Phone: 202-395-6860

-

Available 8:00AM - 6:30PM Weekdays

-
-

All hours in Eastern Time (ET)

+ @if (!string.IsNullOrWhiteSpace(Model.SupportContactBlock)) + { + @Html.Raw(Model.SupportContactBlock) + } + else + { +

MAX Support:

+
+

Email: maxsupport@max.gov

+

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

+
+

Phone: 202-395-6860

+

Available 8:00AM - 6:30PM Weekdays

+
+

All hours in Eastern Time (ET)

+ }
}

(Error Code: @Model.ErrorCode)

diff --git a/Pages/Errors/Template.cshtml.cs b/Pages/Errors/Template.cshtml.cs index 4d91a52..a6a708a 100644 --- a/Pages/Errors/Template.cshtml.cs +++ b/Pages/Errors/Template.cshtml.cs @@ -1,10 +1,21 @@ 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"; @@ -29,13 +40,36 @@ public sealed class TemplateModel : PageModel [FromQuery(Name = "code")] public string ErrorCode { get; set; } = "eaX"; + public string? SupportContactBlock { get; private set; } + public IReadOnlyList InstructionSteps { get; private set; } = new List { "Change some setting" }; - public void OnGet() + 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 diff --git a/Pages/Errors/Unavailable.cshtml b/Pages/Errors/Unavailable.cshtml index e4c38ed..bf54e19 100644 --- a/Pages/Errors/Unavailable.cshtml +++ b/Pages/Errors/Unavailable.cshtml @@ -8,30 +8,37 @@ - MAX - Application Unavailable + MAX - @Model.Title
MAX
-

Application Unavailable

+

@Model.Title

-

MAX applications may be down for scheduled maintenance 2AM-8AM Sunday morning.

-

If you are receiving this message at any other time, please contact MAX Support.

+

@Model.DescriptionLine1

+

@Model.DescriptionLine2

-

MAX Support:

-
-

Email: maxsupport@max.gov

-

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

-
-

Phone: 202-395-6860

-

Available 8:00AM - 6:30PM Weekdays

-
-

All hours in Eastern Time (ET)

+ @if (!string.IsNullOrWhiteSpace(Model.SupportContactBlock)) + { + @Html.Raw(Model.SupportContactBlock) + } + else + { +

MAX Support:

+
+

Email: maxsupport@max.gov

+

Available
 
8:00AM - 8:00PM Weekdays,
9:00AM - 6:00PM Weekends (2 hour response time)

+
+

Phone: 202-395-6860

+

Available 8:00AM - 6:30PM Weekdays

+
+

All hours in Eastern Time (ET)

+ }
-

(Error Code: eau)

+

(Error Code: @Model.ErrorCode)

diff --git a/Pages/Errors/Unavailable.cshtml.cs b/Pages/Errors/Unavailable.cshtml.cs index 4dfb271..65a119f 100644 --- a/Pages/Errors/Unavailable.cshtml.cs +++ b/Pages/Errors/Unavailable.cshtml.cs @@ -1,10 +1,51 @@ using Microsoft.AspNetCore.Mvc.RazorPages; +using maintenance.Services.Templates; namespace maintenance.Pages.Errors; public sealed class UnavailableModel : PageModel { - public void OnGet() + private readonly ITemplateService _templateService; + + public UnavailableModel(ITemplateService templateService) { + _templateService = templateService; + } + + public string Title { get; private set; } = "Application Unavailable"; + public string DescriptionLine1 { get; private set; } = + "MAX applications may be down for scheduled maintenance 2AM-8AM Sunday morning."; + public string DescriptionLine2 { get; private set; } = + "If you are receiving this message at any other time, please contact MAX Support."; + public string ErrorCode { get; private set; } = "eau"; + public string? SupportContactBlock { get; private set; } + + public async Task OnGetAsync() + { + var template = await _templateService.GetByNameAsync("unavailable", HttpContext.RequestAborted); + if (template is null) + { + return; + } + + Title = string.IsNullOrWhiteSpace(template.Title) ? Title : template.Title; + + if (!string.IsNullOrWhiteSpace(template.Body)) + { + var lines = template.Body + .Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + + if (lines.Length > 0) + { + DescriptionLine1 = lines[0]; + } + + if (lines.Length > 1) + { + DescriptionLine2 = lines[1]; + } + } + + SupportContactBlock = template.SupportContactBlock; } } diff --git a/Program.cs b/Program.cs index 082a887..019582d 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,7 @@ using maintenance.Authentication.Core; using maintenance.Authentication.Providers.AdfsWsFed; using maintenance.Authentication.Providers.Oidc; using maintenance.Data; +using maintenance.Services.Templates; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; @@ -40,6 +41,7 @@ builder.Services.AddDbContext(options => options.UseSqlServer(groupLookupDbConnection); options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); }); +builder.Services.AddScoped(); builder.Services.AddRazorPages(options => { diff --git a/Services/Templates/ITemplateService.cs b/Services/Templates/ITemplateService.cs new file mode 100644 index 0000000..8bb4031 --- /dev/null +++ b/Services/Templates/ITemplateService.cs @@ -0,0 +1,8 @@ +using maintenance.Data.Entities; + +namespace maintenance.Services.Templates; + +public interface ITemplateService +{ + Task GetByNameAsync(string name, CancellationToken cancellationToken = default); +} diff --git a/Services/Templates/TemplateService.cs b/Services/Templates/TemplateService.cs new file mode 100644 index 0000000..9e1945b --- /dev/null +++ b/Services/Templates/TemplateService.cs @@ -0,0 +1,22 @@ +using maintenance.Data; +using maintenance.Data.Entities; +using Microsoft.EntityFrameworkCore; + +namespace maintenance.Services.Templates; + +public sealed class TemplateService : ITemplateService +{ + private readonly AppDbContext _dbContext; + + public TemplateService(AppDbContext dbContext) + { + _dbContext = dbContext; + } + + public Task GetByNameAsync(string name, CancellationToken cancellationToken = default) + { + return _dbContext.Templates + .AsNoTracking() + .FirstOrDefaultAsync(t => t.Name == name, cancellationToken); + } +}