diff --git a/src/Application/Features/Locations/DTOs/LocationDto.cs b/src/Application/Features/Locations/DTOs/LocationDto.cs index adaa31bd..bbc22b08 100644 --- a/src/Application/Features/Locations/DTOs/LocationDto.cs +++ b/src/Application/Features/Locations/DTOs/LocationDto.cs @@ -5,11 +5,11 @@ namespace Cfo.Cats.Application.Features.Locations.DTOs; public record LocationDto { - public int Id { get; init; } - public required string Name { get; init; } - public required GenderProvision GenderProvision { get; init; } + public int Id { get; set; } + public required string Name { get; set; } + public required GenderProvision GenderProvision { get; set; } - public required LocationType LocationType { get; init; } + public required LocationType LocationType { get; set; } /// /// The parent location (currently only supported on community locations) diff --git a/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs b/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs index 7b4f4236..f7c1e9de 100644 --- a/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs +++ b/src/Application/Features/Participants/Commands/SetEnrolmentLocation.cs @@ -21,6 +21,7 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto /// /// The location to assign the enrolment to /// + [Description("Current Location")] public LocationDto CurrentLocation { get; set; } = currentLocation; /// @@ -32,8 +33,10 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto /// A justification for enrolling a participant in a location /// other than where we think they are /// + [Description("Justification reason for alternative enrolment location")] public string? JustificationReason { get; set; } = justificationReason; + [Description("Enrol at an alternative location enrolment")] public bool EnrolFromOtherLocation { get; set; } = enrolmentLocation.Id != currentLocation.Id; public string CacheKey => ParticipantCacheKey.GetCacheKey($"Id:{this.Identifier}"); @@ -72,10 +75,18 @@ public Validator() RuleFor(x => x.EnrolmentLocation) .NotNull(); + + 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 c410da0a..d5f2cc0a 100644 --- a/src/Server.UI/Pages/Enrolments/Components/Location.razor +++ b/src/Server.UI/Pages/Enrolments/Components/Location.razor @@ -1,22 +1,53 @@ @using Cfo.Cats.Application.Features.Locations.DTOs @using Cfo.Cats.Application.Features.Participants.Commands +@inject IStringLocalizer L @if (Model is not null && Locations is not []) { - - + - - - - @foreach (var location in Locations!) + + + + + + + + + + @if (Model.EnrolFromOtherLocation) { - - @location.Name - + + + @foreach (var item in Locations!) + { + + @item.Name + + } + + + + + + } - - + + + @* + + + *@ } diff --git a/src/Server.UI/Pages/Enrolments/Enrolment.razor b/src/Server.UI/Pages/Enrolments/Enrolment.razor index b232589c..5898a431 100644 --- a/src/Server.UI/Pages/Enrolments/Enrolment.razor +++ b/src/Server.UI/Pages/Enrolments/Enrolment.razor @@ -144,7 +144,7 @@ Locations = await Mediator.Send(new GetAllLocationsQuery() { - UserProfile = this.UserProfile! + UserProfile = UserProfile! }); }