diff --git a/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs b/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs
index f725caed..a2623703 100644
--- a/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs
+++ b/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs
@@ -27,7 +27,8 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto
///
/// The location to assign the enrolment to
///
- public LocationDto? EnrolmentLocation { get; set; } = enrolmentLocation;
+ [Description("Alternative Location")]
+ public LocationDto? AlternativeLocation { get; set; } = enrolmentLocation;
///
/// A justification for enrolling a participant in a location
@@ -37,7 +38,7 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto
public string? JustificationReason { get; set; } = justificationReason;
[Description("Enrol at an alternative location enrolment")]
- public bool EnrolFromOtherLocation { get; set; }
+ public bool EnrolFromAlternativeLocation { get; set; }
public string[] CacheKeys => [ParticipantCacheKey.GetCacheKey($"Id:{this.Identifier}")];
public CancellationTokenSource? SharedExpiryTokenSource
@@ -60,7 +61,7 @@ public async Task> Handle(Command request, CancellationToken canc
throw new ConflictException($"Participant {request.Identifier} is already enrolled");
}
- participant.SetEnrolmentLocation(request.EnrolmentLocation?.Id ?? request.CurrentLocation.Id, request.JustificationReason);
+ participant.SetEnrolmentLocation(request.AlternativeLocation?.Id ?? request.CurrentLocation.Id, request.JustificationReason);
return participant.Id;
}
}
@@ -70,21 +71,20 @@ public class Validator : AbstractValidator
public Validator()
{
RuleFor(x => x.CurrentLocation)
- .NotNull();
+ .NotNull()
+ .WithMessage("Current location is unknown or missing");
- RuleFor(x => x.EnrolmentLocation)
- .NotNull();
+ When(x => x.EnrolFromAlternativeLocation, () => {
+ RuleFor(x => x.AlternativeLocation)
+ .NotNull()
+ .WithMessage("You must provide an alternative location");
+
+ RuleFor(x => x.AlternativeLocation)
+ .Must((x, alternativeLocation) => x.CurrentLocation.Id != alternativeLocation!.Id)
+ .When(x => x.AlternativeLocation is not null)
+ .WithMessage("You must provide a different alternative location to the current location");
- When(x => x.EnrolFromOtherLocation, () => {
- RuleFor(x => x.EnrolmentLocation)
- .Must((model, enrolmentLocation) => model.CurrentLocation != enrolmentLocation)
- .WithMessage("Enrolment location must be different when Enrol from another location is selected");
- });
-
- When(x => x.CurrentLocation != x.EnrolmentLocation, () => {
RuleFor(x => x.JustificationReason)
- .NotNull()
- .WithMessage("Justification reason is mandatory when enrolling in a different location")
.NotEmpty()
.WithMessage("Justification reason is mandatory when enrolling in a different location");
});
diff --git a/src/Server.UI/Pages/Enrolments/Components/Location.razor b/src/Server.UI/Pages/Enrolments/Components/Location.razor
index 765df2df..7fdf74eb 100644
--- a/src/Server.UI/Pages/Enrolments/Components/Location.razor
+++ b/src/Server.UI/Pages/Enrolments/Components/Location.razor
@@ -24,19 +24,18 @@
You must select a different enrolment location
}
-
+ Label="@L[Model.GetMemberDescription(x => x.EnrolFromAlternativeLocation)]">
- @if (Model.EnrolFromOtherLocation)
+ @if (Model.EnrolFromAlternativeLocation)
{
+ Label="@Model.GetMemberDescription(x => x.AlternativeLocation)"
+ @bind-Value="@Model.AlternativeLocation"
+ For="@(()=>Model.AlternativeLocation!)">
@foreach (var item in Locations!)
{
@@ -78,7 +77,7 @@
{
if (Model is not null && Locations is not null && Locations.Any(l => l.Id == Model!.CurrentLocation.Id) == false)
{
- Model!.EnrolFromOtherLocation = true;
+ Model!.EnrolFromAlternativeLocation = true;
_mustEnrolInOtherLocation = true;
}
}