diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml
new file mode 100644
index 000000000..30127a8a0
--- /dev/null
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml
@@ -0,0 +1,91 @@
+@page "/alerts/{alertId}/delete/check-answers/{handler?}"
+@model TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert.CheckAnswersModel
+@{
+ ViewBag.Title = "Check details and delete alert";
+}
+
+@section BeforeContent {
+ Back
+}
+
+
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs
similarity index 61%
rename from TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml.cs
rename to TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs
index c74a51b65..edf160131 100644
--- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml.cs
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs
@@ -1,15 +1,13 @@
-using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.DataStore.Postgres;
using TeachingRecordSystem.Core.Services.Files;
-using TeachingRecordSystem.SupportUi.Infrastructure.DataAnnotations;
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert;
[Journey(JourneyNames.DeleteAlert), RequireJourneyInstance]
-public class ConfirmModel(
+public class CheckAnswersModel(
TrsDbContext dbContext,
TrsLinkGenerator linkGenerator,
IFileService fileService,
@@ -38,49 +36,17 @@ public class ConfirmModel(
public DateOnly? EndDate { get; set; }
- [BindProperty]
- [Display(Name = "Do you want to add additional detail?")]
- [Required(ErrorMessage = "Select yes if you want to add additional detail")]
- public bool? HasAdditionalDetail { get; set; }
+ public string? DeleteReasonDetail { get; set; }
- [BindProperty]
- [Display(Name = "Add additional detail")]
- public string? AdditionalDetail { get; set; }
+ public string? EvidenceFileName { get; set; }
- [BindProperty]
- [Display(Name = "Upload evidence")]
- [Required(ErrorMessage = "Select yes if you want to upload evidence")]
- public bool? UploadEvidence { get; set; }
+ public string? EvidenceFileSizeDescription { get; set; }
- [BindProperty]
- [EvidenceFile]
- [FileSize(MaxFileSizeMb * 1024 * 1024, ErrorMessage = "The selected file must be smaller than 50MB")]
- public IFormFile? EvidenceFile { get; set; }
+ public string? UploadedEvidenceFileUrl { get; set; }
public async Task OnPost()
{
- if (HasAdditionalDetail == true && AdditionalDetail is null)
- {
- ModelState.AddModelError(nameof(AdditionalDetail), "Add additional detail");
- }
-
- if (UploadEvidence == true && EvidenceFile is null)
- {
- ModelState.AddModelError(nameof(EvidenceFile), "Select a file");
- }
-
- if (!ModelState.IsValid)
- {
- return this.PageWithErrors();
- }
-
var now = clock.UtcNow;
- Guid? evidenceFileId = null;
- if (UploadEvidence == true)
- {
- using var stream = EvidenceFile!.OpenReadStream();
- evidenceFileId = await fileService.UploadFile(stream, EvidenceFile.ContentType);
- }
var alert = await dbContext.Alerts
.SingleAsync(a => a.AlertId == AlertId);
@@ -95,15 +61,15 @@ public async Task OnPost()
CreatedUtc = now,
RaisedBy = User.GetUserId(),
PersonId = PersonId,
- Alert = EventModels.Alert.FromModel(alert),
- DeletionReasonDetail = HasAdditionalDetail == true ? AdditionalDetail : null,
- EvidenceFile = evidenceFileId is Guid fileId ?
+ Alert = oldAlertEventModel,
+ DeletionReasonDetail = DeleteReasonDetail,
+ EvidenceFile = JourneyInstance!.State.EvidenceFileId is Guid fileId ?
new EventModels.File()
{
FileId = fileId,
- Name = EvidenceFile!.FileName
+ Name = JourneyInstance.State.EvidenceFileName!
} :
- null
+ null,
};
dbContext.AddEvent(deletedEvent);
@@ -124,7 +90,7 @@ public async Task OnPostCancel()
public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
- if (JourneyInstance!.State.ConfirmDelete is null)
+ if (!JourneyInstance!.State.IsComplete)
{
context.Result = Redirect(linkGenerator.AlertDelete(AlertId, JourneyInstance.InstanceId));
return;
@@ -140,6 +106,11 @@ public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingConte
Link = alertInfo.Alert.ExternalLink;
StartDate = alertInfo.Alert.StartDate;
EndDate = alertInfo.Alert.EndDate;
+ DeleteReasonDetail = JourneyInstance.State.DeleteReasonDetail;
+ EvidenceFileName = JourneyInstance.State.EvidenceFileName;
+ UploadedEvidenceFileUrl = JourneyInstance!.State.EvidenceFileId is not null ?
+ await fileService.GetFileUrl(JourneyInstance!.State.EvidenceFileId!.Value, _fileUrlExpiresAfter) :
+ null;
await next();
}
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml
deleted file mode 100644
index 23d3bcec6..000000000
--- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Confirm.cshtml
+++ /dev/null
@@ -1,89 +0,0 @@
-@page "/alerts/{alertId}/delete/confirm/{handler?}"
-@model TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert.ConfirmModel
-@{
- ViewBag.Title = "Delete this alert";
-}
-
-@section BeforeContent {
- Back
-}
-
-
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/DeleteAlertState.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/DeleteAlertState.cs
index fd7cd5903..426c51edc 100644
--- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/DeleteAlertState.cs
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/DeleteAlertState.cs
@@ -1,3 +1,6 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Text.Json.Serialization;
+
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert;
public class DeleteAlertState : IRegisterJourney
@@ -8,5 +11,24 @@ public class DeleteAlertState : IRegisterJourney
requestDataKeys: ["alertId"],
appendUniqueKey: true);
- public bool? ConfirmDelete { get; set; }
+ public bool? HasAdditionalReasonDetail { get; set; }
+
+ public string? DeleteReasonDetail { get; set; }
+
+ public bool? UploadEvidence { get; set; }
+
+ public Guid? EvidenceFileId { get; set; }
+
+ public string? EvidenceFileName { get; set; }
+
+ public string? EvidenceFileSizeDescription { get; set; }
+
+ [JsonIgnore]
+ [MemberNotNullWhen(true, nameof(HasAdditionalReasonDetail), nameof(UploadEvidence), nameof(EvidenceFileId))]
+ public bool IsComplete =>
+ HasAdditionalReasonDetail.HasValue &&
+ (!HasAdditionalReasonDetail.Value || (HasAdditionalReasonDetail.Value && !string.IsNullOrWhiteSpace(DeleteReasonDetail))) &&
+ UploadEvidence.HasValue &&
+ (!UploadEvidence.Value || (UploadEvidence.Value && EvidenceFileId.HasValue));
+
}
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Index.cshtml
index 489980255..3f095e417 100644
--- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Index.cshtml
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/Index.cshtml
@@ -1,57 +1,55 @@
@page "/alerts/{alertId}/delete/{handler?}"
@model TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert.IndexModel
@{
- ViewBag.Title = "Delete this alert";
+ ViewBag.Title = $"Delete {Model.AlertTypeName} alert";
}
@section BeforeContent {
- Back
+ Back
}