From ddfedf54366a1adf8a3890a2faf13cc8d11e524c Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Mon, 18 Nov 2024 16:30:33 +0000 Subject: [PATCH 01/46] added link to International Identifiers --- .../CO.CDP.OrganisationApp.csproj | 4 + .../OrganisationIdentification.cshtml | 247 +++++++++--------- 2 files changed, 130 insertions(+), 121 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj index ef224da5d..d169476ee 100644 --- a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj +++ b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj @@ -28,4 +28,8 @@ + + + + diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml index 89ff6fa41..f52b83167 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml @@ -13,7 +13,7 @@ var jerseyFinancialServicesCommissionRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber)).HasInnerHtml; var isleofManCompaniesRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber)).HasInnerHtml; - var ukLearningProviderReferenceNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber)).HasInnerHtml; + var ukLearningProviderReferenceNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber)).HasInnerHtml; var nationalHealthServiceOrganisationsRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber)).HasInnerHtml; @@ -26,142 +26,147 @@ } -
-
- -
- @if (Request.Query.ContainsKey("frm-summary")) - { - - } -
-
- -

- @ViewData["Title"] -

-
-
- Select all that apply. Then enter the registration number. -
-
-
- - @Html.LabelFor(m => m.CharityCommissionEnglandWales, new { @class = "govuk-label govuk-radios__label", @for = "GB-CHC" }) -
-
-
- @Html.LabelFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-label", @for = Model.CharityCommissionEnglandWalesNumber }) - @Html.ValidationMessageFor(m => m.CharityCommissionEnglandWalesNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionEnglandWalesNumber-error" }) - @Html.TextBoxFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-input " + (charityCommissionEnglandWalesNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionEnglandWalesNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+
+ + + @if (Request.Query.ContainsKey("frm-summary")) + { + + } +
+
+ +

+ @ViewData["Title"] +

+
+
+ Select all that apply. Then enter the registration number. +
+

+ + Enter a non-UK registry and number + +

+
+
+ + @Html.LabelFor(m => m.CharityCommissionEnglandWales, new { @class = "govuk-label govuk-radios__label", @for = "GB-CHC" }) +
+
+
+ @Html.LabelFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-label", @for = Model.CharityCommissionEnglandWalesNumber }) + @Html.ValidationMessageFor(m => m.CharityCommissionEnglandWalesNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionEnglandWalesNumber-error" }) + @Html.TextBoxFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-input " + (charityCommissionEnglandWalesNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionEnglandWalesNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.ScottishCharityRegulator, new { @class = "govuk-label govuk-radios__label", @for = "GB-SC" }) -
-
-
- @Html.LabelFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-label", @for = Model.ScottishCharityRegulatorNumber }) - @Html.ValidationMessageFor(m => m.ScottishCharityRegulatorNumber, "", new { @class = "govuk-error-message", @id = "ScottishCharityRegulatorNumber-error" }) - @Html.TextBoxFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-input " + (scottishCharityRegulatorNumberHasError ? "govuk-input--error" : ""), @id = "ScottishCharityRegulatorNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.ScottishCharityRegulator, new { @class = "govuk-label govuk-radios__label", @for = "GB-SC" }) +
+
+
+ @Html.LabelFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-label", @for = Model.ScottishCharityRegulatorNumber }) + @Html.ValidationMessageFor(m => m.ScottishCharityRegulatorNumber, "", new { @class = "govuk-error-message", @id = "ScottishCharityRegulatorNumber-error" }) + @Html.TextBoxFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-input " + (scottishCharityRegulatorNumberHasError ? "govuk-input--error" : ""), @id = "ScottishCharityRegulatorNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.CharityCommissionNorthernIreland, new { @class = "govuk-label govuk-radios__label", @for = "GB-NIC" }) -
-
-
- @Html.LabelFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-label", @for = Model.CharityCommissionNorthernIrelandNumber }) - @Html.ValidationMessageFor(m => m.CharityCommissionNorthernIrelandNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionNorthernIrelandNumber-error" }) - @Html.TextBoxFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-input " + (charityCommissionNorthernIrelandNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionNorthernIrelandNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.CharityCommissionNorthernIreland, new { @class = "govuk-label govuk-radios__label", @for = "GB-NIC" }) +
+
+
+ @Html.LabelFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-label", @for = Model.CharityCommissionNorthernIrelandNumber }) + @Html.ValidationMessageFor(m => m.CharityCommissionNorthernIrelandNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionNorthernIrelandNumber-error" }) + @Html.TextBoxFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-input " + (charityCommissionNorthernIrelandNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionNorthernIrelandNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.MutualsPublicRegister, new { @class = "govuk-label govuk-radios__label", @for = "GB-MPR" }) -
-
-
- @Html.LabelFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-label", @for = Model.MutualsPublicRegisterNumber }) - @Html.ValidationMessageFor(m => m.MutualsPublicRegisterNumber, "", new { @class = "govuk-error-message", @id = "MutualsPublicRegisterNumber-error" }) - @Html.TextBoxFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-input " + (mutualsPublicRegisterNumberHasError ? "govuk-input--error" : ""), @id = "MutualsPublicRegisterNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.MutualsPublicRegister, new { @class = "govuk-label govuk-radios__label", @for = "GB-MPR" }) +
+
+
+ @Html.LabelFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-label", @for = Model.MutualsPublicRegisterNumber }) + @Html.ValidationMessageFor(m => m.MutualsPublicRegisterNumber, "", new { @class = "govuk-error-message", @id = "MutualsPublicRegisterNumber-error" }) + @Html.TextBoxFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-input " + (mutualsPublicRegisterNumberHasError ? "govuk-input--error" : ""), @id = "MutualsPublicRegisterNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.GuernseyRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GG-RCE" }) -
-
-
- @Html.LabelFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-label", @for = Model.GuernseyRegistryNumber }) - @Html.ValidationMessageFor(m => m.GuernseyRegistryNumber, "", new { @class = "govuk-error-message", @id = "GuernseyRegistryNumber-error" }) - @Html.TextBoxFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-input " + (guernseyRegistryNumberHasError ? "govuk-input--error" : ""), @id = "GuernseyRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.GuernseyRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GG-RCE" }) +
+
+
+ @Html.LabelFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-label", @for = Model.GuernseyRegistryNumber }) + @Html.ValidationMessageFor(m => m.GuernseyRegistryNumber, "", new { @class = "govuk-error-message", @id = "GuernseyRegistryNumber-error" }) + @Html.TextBoxFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-input " + (guernseyRegistryNumberHasError ? "govuk-input--error" : ""), @id = "GuernseyRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistry, new { @class = "govuk-label govuk-radios__label", @for = "JE-FSC" }) -
-
-
- @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-label", @for = Model.JerseyFinancialServicesCommissionRegistryNumber }) - @Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, "", new { @class = "govuk-error-message", @id = "JerseyFinancialServicesCommissionRegistryNumber-error" }) - @Html.TextBoxFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-input " + (jerseyFinancialServicesCommissionRegistryNumberHasError ? "govuk-input--error" : ""), @id = "JerseyFinancialServicesCommissionRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistry, new { @class = "govuk-label govuk-radios__label", @for = "JE-FSC" }) +
+
+
+ @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-label", @for = Model.JerseyFinancialServicesCommissionRegistryNumber }) + @Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, "", new { @class = "govuk-error-message", @id = "JerseyFinancialServicesCommissionRegistryNumber-error" }) + @Html.TextBoxFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-input " + (jerseyFinancialServicesCommissionRegistryNumberHasError ? "govuk-input--error" : ""), @id = "JerseyFinancialServicesCommissionRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.IsleofManCompaniesRegistry, new { @class = "govuk-label govuk-radios__label", @for = "IM-CR" }) -
-
-
- @Html.LabelFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-label", @for = Model.IsleofManCompaniesRegistryNumber }) - @Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber, "", new { @class = "govuk-error-message", @id = "IsleofManCompaniesRegistryNumber-error" }) - @Html.TextBoxFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-input " + (isleofManCompaniesRegistryNumberHasError ? "govuk-input--error" : ""), @id = "IsleofManCompaniesRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.IsleofManCompaniesRegistry, new { @class = "govuk-label govuk-radios__label", @for = "IM-CR" }) +
+
+
+ @Html.LabelFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-label", @for = Model.IsleofManCompaniesRegistryNumber }) + @Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber, "", new { @class = "govuk-error-message", @id = "IsleofManCompaniesRegistryNumber-error" }) + @Html.TextBoxFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-input " + (isleofManCompaniesRegistryNumberHasError ? "govuk-input--error" : ""), @id = "IsleofManCompaniesRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GB-NHS" }) -
-
-
- @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-label", @for = Model.NationalHealthServiceOrganisationsRegistryNumber }) - @Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, "", new { @class = "govuk-error-message", @id = "NationalHealthServiceOrganisationsRegistryNumber-error" }) - @Html.TextBoxFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-input " + (nationalHealthServiceOrganisationsRegistryNumberHasError ? "govuk-input--error" : ""), @id = "NationalHealthServiceOrganisationsRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GB-NHS" }) +
+
+
+ @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-label", @for = Model.NationalHealthServiceOrganisationsRegistryNumber }) + @Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, "", new { @class = "govuk-error-message", @id = "NationalHealthServiceOrganisationsRegistryNumber-error" }) + @Html.TextBoxFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-input " + (nationalHealthServiceOrganisationsRegistryNumberHasError ? "govuk-input--error" : ""), @id = "NationalHealthServiceOrganisationsRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.UKLearningProviderReference, new { @class = "govuk-label govuk-radios__label", @for = "VAT" }) -
-
-
- @Html.LabelFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-label", @for = Model.UKLearningProviderReferenceNumber }) - @Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber, "", new { @class = "govuk-error-message", @id = "UKLearningProviderReferenceNumber-error" }) - @Html.TextBoxFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-input " + (ukLearningProviderReferenceNumberHasError ? "govuk-input--error" : ""), @id = "UKLearningProviderReferenceNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
-
- -
or
-
- - @Html.LabelFor(m => m.Other, new { @class = "govuk-label govuk-radios__label", @for = "Other" }) +
+ + @Html.LabelFor(m => m.UKLearningProviderReference, new { @class = "govuk-label govuk-radios__label", @for = "VAT" }) +
+
+
+ @Html.LabelFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-label", @for = Model.UKLearningProviderReferenceNumber }) + @Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber, "", new { @class = "govuk-error-message", @id = "UKLearningProviderReferenceNumber-error" }) + @Html.TextBoxFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-input " + (ukLearningProviderReferenceNumberHasError ? "govuk-input--error" : ""), @id = "UKLearningProviderReferenceNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
-
-
- Continue - -
+ +
or
+
+ + @Html.LabelFor(m => m.Other, new { @class = "govuk-label govuk-radios__label", @for = "Other" }) +
+
+
+
+ Continue +
+
From 92ff4acf9c139a2fa91c67f777adc70797949e07 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 28 Nov 2024 12:47:15 +0000 Subject: [PATCH 02/46] added code for international identifier --- ...InternationalIdentificationCountryTests.cs | 69 ++++++++++ ...isationInternationalIdentificationTests.cs | 130 ++++++++++++++++++ .../CO.CDP.OrganisationApp.csproj | 7 + .../Constants/Country.cs | 106 +++++--------- .../Models/RegistrationDetails.cs | 2 + .../OrganisationIdentification.cshtml | 2 +- ...nisationInternationalIdentification.cshtml | 129 +++++++++++++++++ ...ationInternationalIdentification.cshtml.cs | 128 +++++++++++++++++ ...nInternationalIdentificationCountry.cshtml | 59 ++++++++ ...ternationalIdentificationCountry.cshtml.cs | 37 +++++ .../Registration/OrganisationName.cshtml | 4 + .../Registration/OrganisationName.cshtml.cs | 3 + .../Registration/RegistrationStepModel.cs | 14 ++ .../RequiredIfAttribute.cs | 35 +++++ 14 files changed, 649 insertions(+), 76 deletions(-) create mode 100644 Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationCountryTests.cs create mode 100644 Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationTests.cs create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationCountryTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationCountryTests.cs new file mode 100644 index 000000000..71d86e779 --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationCountryTests.cs @@ -0,0 +1,69 @@ +using CO.CDP.OrganisationApp.Pages.Registration; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc; +using Moq; +using Xunit; +using FluentAssertions; +using Amazon.S3; +using CO.CDP.OrganisationApp.Models; + + +namespace CO.CDP.OrganisationApp.Tests.Pages.Registration; + +public class OrganisationInternationalIdentificationCountryTests +{ + private readonly Mock _sessionMock; + private readonly OrganisationInternationalIdentificationCountryModel _model; + + public OrganisationInternationalIdentificationCountryTests() + { + _sessionMock = new Mock(); + _model = new OrganisationInternationalIdentificationCountryModel(_sessionMock.Object); + + _sessionMock.Setup(session => session.Get(Session.UserDetailsKey)) + .Returns(new UserDetails { UserUrn = "urn:test" }); + + } + + [Fact] + public void OnGet_ShouldSetCountryFromRegistrationDetails() + { + var expectedCountry = "France"; + _model.RegistrationDetails.OrganisationIdentificationCountry = expectedCountry; + + _model.OnGet(); + + _model.Country.Should().Be(expectedCountry); + } + + [Fact] + public void OnPost_InvalidModelState_ShouldReturnPageResult() + { + + _model.Country = null; + _model.ModelState.AddModelError("Country", "Required"); + + var result = _model.OnPost(); + + result.Should().BeOfType(); + } + + [Fact] + public void OnPost_ValidModelState_ShouldUpdateRegistrationDetailsAndRedirect() + { + var country = "France"; + _model.Country = country; + + var result = _model.OnPost(); + + _model.RegistrationDetails.OrganisationIdentificationCountry.Should().Be(country); + + _sessionMock.Verify( + session => session.Set(Session.RegistrationDetailsKey, It.Is(rd => + rd.OrganisationIdentificationCountry == country)), + Times.Once); + + result.Should().BeOfType() + .Which.PageName.Should().Be("OrganisationInternationalIdentification"); + } +} diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationTests.cs new file mode 100644 index 000000000..bb116596c --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationInternationalIdentificationTests.cs @@ -0,0 +1,130 @@ +using Moq; +using FluentAssertions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using CO.CDP.OrganisationApp.Pages.Registration; +using CO.CDP.EntityVerificationClient; +using CO.CDP.Organisation.WebApiClient; + +namespace CO.CDP.OrganisationApp.Tests.Pages.Registration; + +public class OrganisationInternationalIdentificationTests +{ + private readonly Mock _sessionMock = new(); + private readonly Mock _organisationClientMock = new(); + private readonly Mock _pponClientMock = new(); + private readonly Mock _tempDataServiceMock = new(); + private static readonly Guid _organisationId = Guid.NewGuid(); + + private OrganisationInternationalIdentificationModel CreateModel() + { + return new OrganisationInternationalIdentificationModel( + _sessionMock.Object, + _organisationClientMock.Object, + _pponClientMock.Object, + _tempDataServiceMock.Object + ); + } + + [Fact] + public async Task OnGet_ShouldSetCountryAndOrganisationScheme() + { + var model = CreateModel(); + model.RegistrationDetails.OrganisationIdentificationCountry = "FR"; + model.RegistrationDetails.OrganisationScheme = "ABC"; + + await model.OnGet(); + + model.Country.Should().Be("FR"); + model.OrganisationScheme.Should().Be("ABC"); + } + + [Fact] + public async Task OnGet_ShouldHandleIdentifierRegistriesApiExceptionGracefully() + { + var model = CreateModel(); + _pponClientMock + .Setup(p => p.GetIdentifierRegistriesAsync(It.IsAny())) + .ThrowsAsync(new EntityVerificationClient.ApiException("", 404, "", null, null)); + + Func act = async () => await model.OnGet(); + + await act.Should().NotThrowAsync(); + } + + [Fact] + public async Task OnPost_ShouldReturnPage_WhenModelStateIsInvalid() + { + var model = CreateModel(); + model.ModelState.AddModelError("OrganisationScheme", "Required"); + + var result = await model.OnPost(); + + result.Should().BeOfType(); + } + + [Fact] + public async Task OnPost_ShouldRedirectToOrganisationDetailsSummary_WhenEntityVerificationNotFound() + { + var model = CreateModel(); + model.RedirectToSummary = true; + model.RegistrationDetails.OrganisationScheme = "ABC"; + model.RegistrationDetails.OrganisationIdentificationNumber = "123"; + + _organisationClientMock + .Setup(o => o.LookupOrganisationAsync(It.IsAny(), It.IsAny())) + .ThrowsAsync(new CO.CDP.Organisation.WebApiClient.ApiException("", 404, "", null, null)); + + _pponClientMock + .Setup(p => p.GetIdentifiersAsync(It.IsAny())) + .ThrowsAsync(new EntityVerificationClient.ApiException("", 404, "", null, null)); + + var result = await model.OnPost(); + + result.Should().BeOfType().Which.PageName.Should().Be("OrganisationDetailsSummary"); + } + + [Fact] + public async Task OnPost_ShouldRedirectToOrganisationName_WhenEntityVerificationNotFound() + { + var model = CreateModel(); + model.RedirectToSummary = false; + model.RegistrationDetails.OrganisationScheme = "ABC"; + model.RegistrationDetails.OrganisationIdentificationNumber = "123"; + + _organisationClientMock + .Setup(o => o.LookupOrganisationAsync(It.IsAny(), It.IsAny())) + .ThrowsAsync(new CO.CDP.Organisation.WebApiClient.ApiException("", 404, "", null, null)); + + _pponClientMock + .Setup(p => p.GetIdentifiersAsync(It.IsAny())) + .ThrowsAsync(new EntityVerificationClient.ApiException("", 404, "", null, null)); + + var result = await model.OnPost(); + + result.Should().BeOfType().Which.PageName.Should().Be("OrganisationName"); + } + + [Fact] + public async Task OnPost_ShouldSetFlashMessage_WhenOrganisationAlreadyExists() + { + var model = CreateModel(); + model.Identifier = "ABC:123"; + model.OrganisationName = "Test Organisation"; + + _organisationClientMock + .Setup(o => o.LookupOrganisationAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(GivenOrganisationClientModel()); + + var result = await model.OnPost(); + + _tempDataServiceMock.Verify(t => t.Put(It.IsAny(), It.IsAny()), Times.Once); + result.Should().BeOfType(); + } + + private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel() + { + return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null, contactPoint: null, id: _organisationId, identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: [])); + } +} + diff --git a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj index d169476ee..35d9b1e7c 100644 --- a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj +++ b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj @@ -32,4 +32,11 @@ + + + true + PreserveNewest + + + diff --git a/Frontend/CO.CDP.OrganisationApp/Constants/Country.cs b/Frontend/CO.CDP.OrganisationApp/Constants/Country.cs index 65c179582..c559ef1b6 100644 --- a/Frontend/CO.CDP.OrganisationApp/Constants/Country.cs +++ b/Frontend/CO.CDP.OrganisationApp/Constants/Country.cs @@ -11,22 +11,16 @@ public static class Country new() { {"AF", "Afghanistan"}, - {"AX", "Ă…land Islands"}, {"AL", "Albania"}, {"DZ", "Algeria"}, - {"AS", "American Samoa"}, {"AD", "Andorra"}, {"AO", "Angola"}, - {"AI", "Anguilla"}, - {"AQ", "Antarctica"}, {"AG", "Antigua and Barbuda"}, {"AR", "Argentina"}, {"AM", "Armenia"}, - {"AW", "Aruba"}, {"AU", "Australia"}, {"AT", "Austria"}, {"AZ", "Azerbaijan"}, - {"BS", "Bahamas"}, {"BH", "Bahrain"}, {"BD", "Bangladesh"}, {"BB", "Barbados"}, @@ -34,15 +28,12 @@ public static class Country {"BE", "Belgium"}, {"BZ", "Belize"}, {"BJ", "Benin"}, - {"BM", "Bermuda"}, {"BT", "Bhutan"}, {"BO", "Bolivia"}, {"BA", "Bosnia and Herzegovina"}, {"BW", "Botswana"}, - {"BV", "Bouvet Island"}, {"BR", "Brazil"}, - {"IO", "British Indian Ocean Territory"}, - {"BN", "Brunei Darussalam"}, + {"BN", "Brunei"}, {"BG", "Bulgaria"}, {"BF", "Burkina Faso"}, {"BI", "Burundi"}, @@ -50,93 +41,75 @@ public static class Country {"CM", "Cameroon"}, {"CA", "Canada"}, {"CV", "Cape Verde"}, - {"KY", "Cayman Islands"}, {"CF", "Central African Republic"}, {"TD", "Chad"}, {"CL", "Chile"}, {"CN", "China"}, - {"CX", "Christmas Island"}, - {"CC", "Cocos (Keeling) Islands"}, {"CO", "Colombia"}, {"KM", "Comoros"}, {"CG", "Congo"}, - {"CD", "Congo, The Democratic Republic of the"}, - {"CK", "Cook Islands"}, + {"CD", "Congo (Democratic Republic)"}, {"CR", "Costa Rica"}, {"HR", "Croatia"}, {"CU", "Cuba"}, {"CY", "Cyprus"}, - {"CZ", "Czech Republic"}, + {"CZ", "Czechia"}, {"DK", "Denmark"}, {"DJ", "Djibouti"}, {"DM", "Dominica"}, {"DO", "Dominican Republic"}, + {"TL", "East Timor"}, {"EC", "Ecuador"}, {"EG", "Egypt"}, {"SV", "El Salvador"}, {"GQ", "Equatorial Guinea"}, {"ER", "Eritrea"}, {"EE", "Estonia"}, + {"SZ", "Eswatini"}, {"ET", "Ethiopia"}, - {"FK", "Falkland Islands (Malvinas)"}, - {"FO", "Faroe Islands"}, {"FJ", "Fiji"}, {"FI", "Finland"}, {"FR", "France"}, - {"GF", "French Guiana"}, - {"PF", "French Polynesia"}, - {"TF", "French Southern Territories"}, {"GA", "Gabon"}, - {"GM", "Gambia"}, {"GE", "Georgia"}, {"DE", "Germany"}, {"GH", "Ghana"}, - {"GI", "Gibraltar"}, {"GR", "Greece"}, - {"GL", "Greenland"}, {"GD", "Grenada"}, - {"GP", "Guadeloupe"}, - {"GU", "Guam"}, {"GT", "Guatemala"}, - {"GG", "Guernsey"}, {"GN", "Guinea"}, {"GW", "Guinea-Bissau"}, {"GY", "Guyana"}, {"HT", "Haiti"}, - {"HM", "Heard Island and Mcdonald Islands"}, - {"VA", "Holy See (Vatican City State)"}, {"HN", "Honduras"}, - {"HK", "Hong Kong"}, {"HU", "Hungary"}, {"IS", "Iceland"}, {"IN", "India"}, {"ID", "Indonesia"}, - {"IR", "Iran, Islamic Republic Of"}, + {"IR", "Iran"}, {"IQ", "Iraq"}, {"IE", "Ireland"}, - {"IM", "Isle of Man"}, {"IL", "Israel"}, {"IT", "Italy"}, + {"CI", "Ivory Coast"}, {"JM", "Jamaica"}, {"JP", "Japan"}, - {"JE", "Jersey"}, {"JO", "Jordan"}, {"KZ", "Kazakhstan"}, {"KE", "Kenya"}, {"KI", "Kiribati"}, - {"KR", "Korea, Republic of"}, + {"XK", "Kosovo"}, {"KW", "Kuwait"}, {"KG", "Kyrgyzstan"}, + {"LA", "Laos"}, {"LV", "Latvia"}, {"LB", "Lebanon"}, {"LS", "Lesotho"}, {"LR", "Liberia"}, - {"LY", "Libyan Arab Jamahiriya"}, + {"LY", "Libya"}, {"LI", "Liechtenstein"}, {"LT", "Lithuania"}, {"LU", "Luxembourg"}, - {"MO", "Macao"}, - {"MK", "North Macedonia"}, {"MG", "Madagascar"}, {"MW", "Malawi"}, {"MY", "Malaysia"}, @@ -144,62 +117,51 @@ public static class Country {"ML", "Mali"}, {"MT", "Malta"}, {"MH", "Marshall Islands"}, - {"MQ", "Martinique"}, {"MR", "Mauritania"}, {"MU", "Mauritius"}, - {"YT", "Mayotte"}, {"MX", "Mexico"}, - {"FM", "Micronesia, Federated States of"}, - {"MD", "Moldova, Republic of"}, + {"FM", "Federated States of Micronesia"}, + {"MD", "Moldova"}, {"MC", "Monaco"}, {"MN", "Mongolia"}, - {"MS", "Montserrat"}, + {"ME", "Montenegro"}, {"MA", "Morocco"}, {"MZ", "Mozambique"}, - {"MM", "Myanmar"}, + {"MM", "Myanmar (Burma)"}, {"NA", "Namibia"}, {"NR", "Nauru"}, {"NP", "Nepal"}, {"NL", "Netherlands"}, - {"AN", "Netherlands Antilles"}, - {"NC", "New Caledonia"}, {"NZ", "New Zealand"}, {"NI", "Nicaragua"}, {"NE", "Niger"}, {"NG", "Nigeria"}, - {"NU", "Niue"}, - {"NF", "Norfolk Island"}, - {"MP", "Northern Mariana Islands"}, + {"KP", "North Korea"}, + {"MK", "North Macedonia"}, {"NO", "Norway"}, {"OM", "Oman"}, {"PK", "Pakistan"}, {"PW", "Palau"}, - {"PS", "Palestinian Territory, Occupied"}, {"PA", "Panama"}, {"PG", "Papua New Guinea"}, {"PY", "Paraguay"}, {"PE", "Peru"}, {"PH", "Philippines"}, - {"PN", "Pitcairn Islands"}, {"PL", "Poland"}, {"PT", "Portugal"}, - {"PR", "Puerto Rico"}, {"QA", "Qatar"}, - {"RE", "Reunion"}, {"RO", "Romania"}, - {"RU", "Russian Federation"}, + {"RU", "Russia"}, {"RW", "Rwanda"}, - {"SH", "Saint Helena"}, - {"KN", "Saint Kitts and Nevis"}, - {"LC", "Saint Lucia"}, - {"PM", "Saint Pierre and Miquelon"}, - {"VC", "Saint Vincent and the Grenadines"}, + {"KN", "St Kitts and Nevis"}, + {"LC", "St Lucia"}, + {"VC", "St Vincent"}, {"WS", "Samoa"}, {"SM", "San Marino"}, {"ST", "Sao Tome and Principe"}, {"SA", "Saudi Arabia"}, {"SN", "Senegal"}, - {"CS", "Serbia and Montenegro"}, + {"RS", "Serbia"}, {"SC", "Seychelles"}, {"SL", "Sierra Leone"}, {"SG", "Singapore"}, @@ -208,47 +170,41 @@ public static class Country {"SB", "Solomon Islands"}, {"SO", "Somalia"}, {"ZA", "South Africa"}, - {"GS", "South Georgia and the South Sandwich Islands"}, + {"KR", "South Korea"}, + {"SS", "South Sudan"}, {"ES", "Spain"}, {"LK", "Sri Lanka"}, {"SD", "Sudan"}, {"SR", "Suriname"}, - {"SJ", "Svalbard and Jan Mayen"}, - {"SZ", "Swaziland"}, {"SE", "Sweden"}, {"CH", "Switzerland"}, - {"SY", "Syrian Arab Republic"}, - {"TW", "Taiwan"}, + {"SY", "Syria"}, {"TJ", "Tajikistan"}, - {"TZ", "Tanzania, United Republic of"}, + {"TZ", "Tanzania"}, {"TH", "Thailand"}, - {"TL", "Timor-Leste"}, + {"BS", "The Bahamas"}, + {"GM", "The Gambia"}, {"TG", "Togo"}, - {"TK", "Tokelau"}, {"TO", "Tonga"}, {"TT", "Trinidad and Tobago"}, {"TN", "Tunisia"}, {"TR", "Turkey"}, {"TM", "Turkmenistan"}, - {"TC", "Turks and Caicos Islands"}, {"TV", "Tuvalu"}, {"UG", "Uganda"}, {"UA", "Ukraine"}, {"AE", "United Arab Emirates"}, - {"US", "United States of America"}, - {"UM", "United States Minor Outlying Islands"}, + {"GB", "United Kingdom"}, + {"US", "United States"}, {"UY", "Uruguay"}, {"UZ", "Uzbekistan"}, {"VU", "Vanuatu"}, + {"VA", "Vatican City"}, {"VE", "Venezuela"}, {"VN", "Vietnam"}, - {"VG", "Virgin Islands, British"}, - {"VI", "Virgin Islands, U.S."}, - {"WF", "Wallis and Futuna"}, - {"EH", "Western Sahara"}, {"YE", "Yemen"}, {"ZM", "Zambia"}, - {"ZN", "Zimbabwe"} + {"ZW", "Zimbabwe"} }; // https://www.gov.uk/government/publications/open-standards-for-government/country-codes diff --git a/Frontend/CO.CDP.OrganisationApp/Models/RegistrationDetails.cs b/Frontend/CO.CDP.OrganisationApp/Models/RegistrationDetails.cs index 5106819eb..8a1ad541c 100644 --- a/Frontend/CO.CDP.OrganisationApp/Models/RegistrationDetails.cs +++ b/Frontend/CO.CDP.OrganisationApp/Models/RegistrationDetails.cs @@ -10,6 +10,8 @@ public class RegistrationDetails public string? OrganisationEmailAddress { get; set; } + public string? OrganisationIdentificationCountry { get; set; } + public string? OrganisationIdentificationNumber { get; set; } public string? OrganisationAddressLine1 { get; set; } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml index f52b83167..9216128f3 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml @@ -45,7 +45,7 @@ Select all that apply. Then enter the registration number.

- + Enter a non-UK registry and number

diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml new file mode 100644 index 000000000..0ad57513e --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml @@ -0,0 +1,129 @@ +@page +@attribute [RazorCompiledItemMetadata("RouteTemplate", RegistrationStepModel.OrganisationInternationalIdentifierPage)] +@model CO.CDP.OrganisationApp.Pages.Registration.OrganisationInternationalIdentificationModel +@using CO.CDP.Localization + +@{ + ViewData["Title"] = "Is your organisation on any of these registries?"; + + var backLink = $"{RegistrationStepModel.OrganisationInternationalIdentificationCountryPage}{(Request.Query.ContainsKey("frm-summary") ? "?frm-summary" : "")}"; + + var isSmallClass = ""; +} + +@section BeforeContent { + @if (backLink != null) + { + @StaticTextResource.Global_Back + } +} + +
+
+ +
+ @if (Request.Query.ContainsKey("frm-summary")) + { + + } +
+
+ +

+ @ViewData["Title"] +

+
+ +
+ Select one then enter the registration number +
+ +
+ @if (Model.InternationalIdentifiers != null) + { + int index = 0; + + isSmallClass = Model.InternationalIdentifiers.Count > 10 ? "govuk-radios--small" : ""; + + foreach (var choice in Model.InternationalIdentifiers) + { + var id = index == 0 ? "SelectedOption" : $"SelectedOption-{index}"; + var hasError = ModelState[nameof(Model.RegistrationNumbers)]?.Errors?.Any() ?? false; + var selectedOption = Model.OrganisationScheme == choice.Scheme ? "checked" : ""; + +
+
+ + +
+
+ +
+
+ + @if (hasError) + { + + Error: + @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage + + } + +
+
+ + index++; + } + } +
+
+ + +
+
+
+
+ + @if (ModelState[nameof(Model.RegistrationNumbers)]?.Errors?.Any() ?? false) + { + + Error: + @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage + + } + + +
+
+
+
+
+ + + @StaticTextResource.Global_Continue + + +
+
+
diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs new file mode 100644 index 000000000..9f6ab6ac4 --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs @@ -0,0 +1,128 @@ +using CO.CDP.EntityVerificationClient; +using CO.CDP.Organisation.WebApiClient; +using CO.CDP.OrganisationApp.Models; +using Microsoft.AspNetCore.Mvc; + +using CO.CDP.OrganisationApp.Constants; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel; +using CO.CDP.Mvc.Validation; +using ApiException = CO.CDP.EntityVerificationClient.ApiException; + + +namespace CO.CDP.OrganisationApp.Pages.Registration; + +[ValidateRegistrationStep] +public class OrganisationInternationalIdentificationModel(ISession session, + IOrganisationClient organisationClient, + IPponClient pponClient, + ITempDataService tempDataService) : RegistrationStepModel(session) +{ + public override string CurrentPage => OrganisationInternationalIdentifierPage; + + [BindProperty] + public string? Country { get; set; } + + [BindProperty] + public ICollection InternationalIdentifiers { get; set; } = new List(); + + [BindProperty] + [DisplayName("Organisation Type")] + [Required(ErrorMessage = "Select an option")] + public string? OrganisationScheme { get; set; } + + [BindProperty] + [DisplayName("Registration Number")] + [RequiredIfHasValue(nameof(OrganisationScheme), ErrorMessage = "Enter the number")] + public Dictionary RegistrationNumbers { get; set; } = new Dictionary(); + + [BindProperty] + public bool? RedirectToSummary { get; set; } + + public string? Identifier { get; set; } + + public string? OrganisationName; + + public FlashMessage NotificationBannerCompanyAlreadyRegistered { get { return new FlashMessage($"An organisation with this registration number already exists. Change the registration number or request to join {OrganisationName}."); } } + + public async Task OnGet() + { + Country = RegistrationDetails.OrganisationIdentificationCountry; + OrganisationScheme = RegistrationDetails.OrganisationScheme; + if (!string.IsNullOrEmpty(OrganisationScheme)) + { + RegistrationNumbers[OrganisationScheme] = RegistrationDetails.OrganisationIdentificationNumber; + } + + await IdentifierRegistries(); + } + + private async Task IdentifierRegistries() + { + try + { + InternationalIdentifiers = await pponClient.GetIdentifierRegistriesAsync(Country); + } + catch (ApiException ex) when (ex.StatusCode == 404) + { + // Show other + } + } + + public async Task OnPost() + { + Country = RegistrationDetails.OrganisationIdentificationCountry; + RegistrationDetails.OrganisationScheme = OrganisationScheme; + RegistrationDetails.OrganisationIdentificationNumber = OrganisationScheme != null ? RegistrationNumbers!.GetValueOrDefault(OrganisationScheme) : null; + + if (!ModelState.IsValid) + { + await IdentifierRegistries(); + return Page(); + } + + Identifier = $"{RegistrationDetails.OrganisationScheme}:{RegistrationDetails.OrganisationIdentificationNumber}"; + + try + { + SessionContext.Set(Session.RegistrationDetailsKey, RegistrationDetails); + var organisation = await LookupOrganisationAsync(); + OrganisationName = organisation?.Name; + } + catch (Exception orgApiException) when (orgApiException is CO.CDP.Organisation.WebApiClient.ApiException && ((CO.CDP.Organisation.WebApiClient.ApiException)orgApiException).StatusCode == 404) + { + try + { + await LookupEntityVerificationAsync(); + } + catch (Exception evApiException) when (evApiException is EntityVerificationClient.ApiException eve && eve.StatusCode == 404) + { + if (RedirectToSummary == true) + { + return RedirectToPage("OrganisationDetailsSummary"); + } + else + { + return RedirectToPage("OrganisationName", new { InternationalIdentifier = true }); + } + } + catch + { + return RedirectToPage("OrganisationRegistrationUnavailable"); + } + } + + tempDataService.Put(FlashMessageTypes.Important, NotificationBannerCompanyAlreadyRegistered); + return Page(); + } + + private async Task LookupOrganisationAsync() + { + return await organisationClient.LookupOrganisationAsync(string.Empty, Identifier); + } + + private async Task> LookupEntityVerificationAsync() + { + return await pponClient.GetIdentifiersAsync(Identifier); + } +} diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml new file mode 100644 index 000000000..6f391ed45 --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml @@ -0,0 +1,59 @@ +@page +@attribute [RazorCompiledItemMetadata("RouteTemplate", RegistrationStepModel.OrganisationInternationalIdentificationCountryPage)] +@model CO.CDP.OrganisationApp.Pages.Registration.OrganisationInternationalIdentificationCountryModel +@using CO.CDP.Localization + +@{ + ViewData["Title"] = "Select which country your organisation is registered"; + + var countryHasError = ModelState[nameof(Model.Country)]?.Errors?.Any() ?? false; + var backLink = $"{RegistrationStepModel.OrganisationIdentifierPage}{(Request.Query.ContainsKey("frm-summary") ? "?frm-summary" : "")}"; +} + +@section BeforeContent { + @if (backLink != null) + { + @StaticTextResource.Global_Back + } +} + +
+
+ +
+ @if (Request.Query.ContainsKey("frm-summary")) + { + + } +
+
+ +

+ @ViewData["Title"] +

+
+
+ @if (countryHasError) + { +

+ Error: + @ModelState[nameof(Model.Country)]!.Errors[0].ErrorMessage +

+ } + +
+
+
+ + @StaticTextResource.Global_Continue + + +
+
+
diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs new file mode 100644 index 000000000..799659b4a --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs @@ -0,0 +1,37 @@ +using CO.CDP.OrganisationApp.Models; +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + + +namespace CO.CDP.OrganisationApp.Pages.Registration; + +[ValidateRegistrationStep] +public class OrganisationInternationalIdentificationCountryModel(ISession session) : RegistrationStepModel(session) +{ + public override string CurrentPage => OrganisationInternationalIdentificationCountryPage; + + [BindProperty] + [DisplayName("Select which country your organisation is registered")] + [Required(ErrorMessage = "Select a country")] + public string? Country { get; set; } = string.Empty; + + public void OnGet() + { + Country = RegistrationDetails.OrganisationIdentificationCountry; + } + + public IActionResult OnPost() + { + if (!ModelState.IsValid) + { + return Page(); + } + + RegistrationDetails.OrganisationIdentificationCountry = Country; + + SessionContext.Set(Session.RegistrationDetailsKey, RegistrationDetails); + + return RedirectToPage("OrganisationInternationalIdentification"); + } +} \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml index a856afad6..fce034329 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml @@ -17,6 +17,10 @@ { backLink = RegistrationStepModel.OrganisationHasCompanyHouseNumberPage; } + else if (Model.InternationalIdentifier == true) + { + backLink = RegistrationStepModel.OrganisationInternationalIdentifierPage; + } } @section BeforeContent { diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml.cs index 35a4528a4..a31b6482f 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationName.cshtml.cs @@ -12,6 +12,9 @@ public class OrganisationNameModel(ISession session, ICompaniesHouseApi companie { public override string CurrentPage => OrganisationNamePage; + [BindProperty(SupportsGet = true)] + public bool InternationalIdentifier { get; set; } = false; + [BindProperty] [DisplayName(nameof(StaticTextResource.OrganisationRegistration_EnterOrganisationName_Heading))] [Required(ErrorMessage = nameof(StaticTextResource.OrganisationRegistration_EnterOrganisationName_Heading))] diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/RegistrationStepModel.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/RegistrationStepModel.cs index 5d1c847bd..c5fbe87b5 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/RegistrationStepModel.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/RegistrationStepModel.cs @@ -8,6 +8,8 @@ public abstract class RegistrationStepModel : LoggedInUserAwareModel public const string OrganisationTypePage = "/registration/organisation-type"; public const string OrganisationHasCompanyHouseNumberPage = "/registration/has-companies-house-number"; public const string OrganisationIdentifierPage = "/registration/organisation-identification"; + public const string OrganisationInternationalIdentificationCountryPage = "/registration/organisation-identification-country"; + public const string OrganisationInternationalIdentifierPage = "/registration/organisation-identification-identification"; public const string OrganisationNamePage = "/registration/organisation-name"; public const string OrganisationEmailPage = "/registration/organisation-email"; public const string OrganisationAddressPage = "/registration/organisation-registered-address/uk"; @@ -35,6 +37,8 @@ public bool ValidateStep() { OrganisationTypePage => true, OrganisationHasCompanyHouseNumberPage or OrganisationIdentifierPage => ValidType(), + OrganisationInternationalIdentificationCountryPage => ValidType(), + OrganisationInternationalIdentifierPage => ValidType() && ValidCountry(), OrganisationNamePage => ValidType() && ValidIdentifier(), OrganisationEmailPage => ValidType() && ValidIdentifier() && ValidName(), OrganisationAddressPage or OrganisationNonUKAddressPage => ValidType() && ValidIdentifier() && ValidName() && ValidEmail(), @@ -88,6 +92,16 @@ private bool ValidName() return true; } + private bool ValidCountry() + { + if (RegistrationDetails.OrganisationIdentificationCountry == null) + { + ToRedirectPageUrl = OrganisationInternationalIdentificationCountryPage; + return false; + } + return true; + } + private bool ValidEmail() { if (RegistrationDetails.OrganisationEmailAddress == null) diff --git a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs index b442a5bc9..5c4f6d868 100644 --- a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs +++ b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs @@ -21,6 +21,41 @@ protected override ValidationResult IsValid(object? value, ValidationContext val } } +public class RequiredIfHasValueAttribute : ValidationAttribute +{ + private readonly string _organisationSchemeProperty; + + public RequiredIfHasValueAttribute(string organisationSchemeProperty) + { + _organisationSchemeProperty = organisationSchemeProperty; + } + + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) + { + var model = validationContext.ObjectInstance; + var organisationSchemeProperty = model.GetType().GetProperty(_organisationSchemeProperty); + var organisationSchemeValue = organisationSchemeProperty?.GetValue(model) as string; + + if (value is Dictionary registrationNumbers) + { + if (!string.IsNullOrEmpty(organisationSchemeValue) && + registrationNumbers.TryGetValue(organisationSchemeValue, out var registrationNumberValue)) + { + if (string.IsNullOrEmpty(registrationNumberValue)) + { + return new ValidationResult(ErrorMessage ?? "Enter the number."); + } + } + } + else if (!string.IsNullOrEmpty(organisationSchemeValue) && value == null) + { + return new ValidationResult("Enter the number."); + } + + return ValidationResult.Success; + } +} + public class RequiredIfContainsAttribute(string dependentProperty, string containsValue) : RequiredAttribute { protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) From 1c2e21a12b130dcaa141d7572f36fa92bab7fb5f Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 28 Nov 2024 12:57:22 +0000 Subject: [PATCH 03/46] added link for non-uk indentifier --- .../OrganisationIdentification.cshtml | 247 +++++++++--------- 1 file changed, 126 insertions(+), 121 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml index 8b77bd300..586e3764e 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml @@ -14,7 +14,7 @@ var jerseyFinancialServicesCommissionRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber)).HasInnerHtml; var isleofManCompaniesRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber)).HasInnerHtml; - var ukLearningProviderReferenceNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber)).HasInnerHtml; + var ukLearningProviderReferenceNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber)).HasInnerHtml; var nationalHealthServiceOrganisationsRegistryNumberHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber)).HasInnerHtml; @@ -27,142 +27,147 @@ } -
-
- -
- @if (Request.Query.ContainsKey("frm-summary")) - { - - } -
-
- -

- @ViewData["Title"] -

-
-
- @StaticTextResource.Organisation_OrganisationIdentification_Hint -
-
-
- - @Html.LabelFor(m => m.CharityCommissionEnglandWales, new { @class = "govuk-label govuk-radios__label", @for = "GB-CHC" }) -
-
-
- @Html.LabelFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-label", @for = Model.CharityCommissionEnglandWalesNumber }) - @Html.ValidationMessageFor(m => m.CharityCommissionEnglandWalesNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionEnglandWalesNumber-error" }) - @Html.TextBoxFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-input " + (charityCommissionEnglandWalesNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionEnglandWalesNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+
+ + + @if (Request.Query.ContainsKey("frm-summary")) + { + + } +
+
+ +

+ @ViewData["Title"] +

+
+
+ @StaticTextResource.Organisation_OrganisationIdentification_Hint +
+

+ + Enter a non-UK registry and number + +

+
+
+ + @Html.LabelFor(m => m.CharityCommissionEnglandWales, new { @class = "govuk-label govuk-radios__label", @for = "GB-CHC" }) +
+
+
+ @Html.LabelFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-label", @for = Model.CharityCommissionEnglandWalesNumber }) + @Html.ValidationMessageFor(m => m.CharityCommissionEnglandWalesNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionEnglandWalesNumber-error" }) + @Html.TextBoxFor(m => m.CharityCommissionEnglandWalesNumber, new { @class = "govuk-input " + (charityCommissionEnglandWalesNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionEnglandWalesNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.ScottishCharityRegulator, new { @class = "govuk-label govuk-radios__label", @for = "GB-SC" }) -
-
-
- @Html.LabelFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-label", @for = Model.ScottishCharityRegulatorNumber }) - @Html.ValidationMessageFor(m => m.ScottishCharityRegulatorNumber, "", new { @class = "govuk-error-message", @id = "ScottishCharityRegulatorNumber-error" }) - @Html.TextBoxFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-input " + (scottishCharityRegulatorNumberHasError ? "govuk-input--error" : ""), @id = "ScottishCharityRegulatorNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.ScottishCharityRegulator, new { @class = "govuk-label govuk-radios__label", @for = "GB-SC" }) +
+
+
+ @Html.LabelFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-label", @for = Model.ScottishCharityRegulatorNumber }) + @Html.ValidationMessageFor(m => m.ScottishCharityRegulatorNumber, "", new { @class = "govuk-error-message", @id = "ScottishCharityRegulatorNumber-error" }) + @Html.TextBoxFor(m => m.ScottishCharityRegulatorNumber, new { @class = "govuk-input " + (scottishCharityRegulatorNumberHasError ? "govuk-input--error" : ""), @id = "ScottishCharityRegulatorNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.CharityCommissionNorthernIreland, new { @class = "govuk-label govuk-radios__label", @for = "GB-NIC" }) -
-
-
- @Html.LabelFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-label", @for = Model.CharityCommissionNorthernIrelandNumber }) - @Html.ValidationMessageFor(m => m.CharityCommissionNorthernIrelandNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionNorthernIrelandNumber-error" }) - @Html.TextBoxFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-input " + (charityCommissionNorthernIrelandNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionNorthernIrelandNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.CharityCommissionNorthernIreland, new { @class = "govuk-label govuk-radios__label", @for = "GB-NIC" }) +
+
+
+ @Html.LabelFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-label", @for = Model.CharityCommissionNorthernIrelandNumber }) + @Html.ValidationMessageFor(m => m.CharityCommissionNorthernIrelandNumber, "", new { @class = "govuk-error-message", @id = "CharityCommissionNorthernIrelandNumber-error" }) + @Html.TextBoxFor(m => m.CharityCommissionNorthernIrelandNumber, new { @class = "govuk-input " + (charityCommissionNorthernIrelandNumberHasError ? "govuk-input--error" : ""), @id = "CharityCommissionNorthernIrelandNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.MutualsPublicRegister, new { @class = "govuk-label govuk-radios__label", @for = "GB-MPR" }) -
-
-
- @Html.LabelFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-label", @for = Model.MutualsPublicRegisterNumber }) - @Html.ValidationMessageFor(m => m.MutualsPublicRegisterNumber, "", new { @class = "govuk-error-message", @id = "MutualsPublicRegisterNumber-error" }) - @Html.TextBoxFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-input " + (mutualsPublicRegisterNumberHasError ? "govuk-input--error" : ""), @id = "MutualsPublicRegisterNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.MutualsPublicRegister, new { @class = "govuk-label govuk-radios__label", @for = "GB-MPR" }) +
+
+
+ @Html.LabelFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-label", @for = Model.MutualsPublicRegisterNumber }) + @Html.ValidationMessageFor(m => m.MutualsPublicRegisterNumber, "", new { @class = "govuk-error-message", @id = "MutualsPublicRegisterNumber-error" }) + @Html.TextBoxFor(m => m.MutualsPublicRegisterNumber, new { @class = "govuk-input " + (mutualsPublicRegisterNumberHasError ? "govuk-input--error" : ""), @id = "MutualsPublicRegisterNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.GuernseyRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GG-RCE" }) -
-
-
- @Html.LabelFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-label", @for = Model.GuernseyRegistryNumber }) - @Html.ValidationMessageFor(m => m.GuernseyRegistryNumber, "", new { @class = "govuk-error-message", @id = "GuernseyRegistryNumber-error" }) - @Html.TextBoxFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-input " + (guernseyRegistryNumberHasError ? "govuk-input--error" : ""), @id = "GuernseyRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.GuernseyRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GG-RCE" }) +
+
+
+ @Html.LabelFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-label", @for = Model.GuernseyRegistryNumber }) + @Html.ValidationMessageFor(m => m.GuernseyRegistryNumber, "", new { @class = "govuk-error-message", @id = "GuernseyRegistryNumber-error" }) + @Html.TextBoxFor(m => m.GuernseyRegistryNumber, new { @class = "govuk-input " + (guernseyRegistryNumberHasError ? "govuk-input--error" : ""), @id = "GuernseyRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistry, new { @class = "govuk-label govuk-radios__label", @for = "JE-FSC" }) -
-
-
- @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-label", @for = Model.JerseyFinancialServicesCommissionRegistryNumber }) - @Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, "", new { @class = "govuk-error-message", @id = "JerseyFinancialServicesCommissionRegistryNumber-error" }) - @Html.TextBoxFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-input " + (jerseyFinancialServicesCommissionRegistryNumberHasError ? "govuk-input--error" : ""), @id = "JerseyFinancialServicesCommissionRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistry, new { @class = "govuk-label govuk-radios__label", @for = "JE-FSC" }) +
+
+
+ @Html.LabelFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-label", @for = Model.JerseyFinancialServicesCommissionRegistryNumber }) + @Html.ValidationMessageFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, "", new { @class = "govuk-error-message", @id = "JerseyFinancialServicesCommissionRegistryNumber-error" }) + @Html.TextBoxFor(m => m.JerseyFinancialServicesCommissionRegistryNumber, new { @class = "govuk-input " + (jerseyFinancialServicesCommissionRegistryNumberHasError ? "govuk-input--error" : ""), @id = "JerseyFinancialServicesCommissionRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.IsleofManCompaniesRegistry, new { @class = "govuk-label govuk-radios__label", @for = "IM-CR" }) -
-
-
- @Html.LabelFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-label", @for = Model.IsleofManCompaniesRegistryNumber }) - @Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber, "", new { @class = "govuk-error-message", @id = "IsleofManCompaniesRegistryNumber-error" }) - @Html.TextBoxFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-input " + (isleofManCompaniesRegistryNumberHasError ? "govuk-input--error" : ""), @id = "IsleofManCompaniesRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.IsleofManCompaniesRegistry, new { @class = "govuk-label govuk-radios__label", @for = "IM-CR" }) +
+
+
+ @Html.LabelFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-label", @for = Model.IsleofManCompaniesRegistryNumber }) + @Html.ValidationMessageFor(m => m.IsleofManCompaniesRegistryNumber, "", new { @class = "govuk-error-message", @id = "IsleofManCompaniesRegistryNumber-error" }) + @Html.TextBoxFor(m => m.IsleofManCompaniesRegistryNumber, new { @class = "govuk-input " + (isleofManCompaniesRegistryNumberHasError ? "govuk-input--error" : ""), @id = "IsleofManCompaniesRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GB-NHS" }) -
-
-
- @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-label", @for = Model.NationalHealthServiceOrganisationsRegistryNumber }) - @Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, "", new { @class = "govuk-error-message", @id = "NationalHealthServiceOrganisationsRegistryNumber-error" }) - @Html.TextBoxFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-input " + (nationalHealthServiceOrganisationsRegistryNumberHasError ? "govuk-input--error" : ""), @id = "NationalHealthServiceOrganisationsRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
+
+ + @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistry, new { @class = "govuk-label govuk-radios__label", @for = "GB-NHS" }) +
+
+
+ @Html.LabelFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-label", @for = Model.NationalHealthServiceOrganisationsRegistryNumber }) + @Html.ValidationMessageFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, "", new { @class = "govuk-error-message", @id = "NationalHealthServiceOrganisationsRegistryNumber-error" }) + @Html.TextBoxFor(m => m.NationalHealthServiceOrganisationsRegistryNumber, new { @class = "govuk-input " + (nationalHealthServiceOrganisationsRegistryNumberHasError ? "govuk-input--error" : ""), @id = "NationalHealthServiceOrganisationsRegistryNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
+
-
- - @Html.LabelFor(m => m.UKLearningProviderReference, new { @class = "govuk-label govuk-radios__label", @for = "VAT" }) -
-
-
- @Html.LabelFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-label", @for = Model.UKLearningProviderReferenceNumber }) - @Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber, "", new { @class = "govuk-error-message", @id = "UKLearningProviderReferenceNumber-error" }) - @Html.TextBoxFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-input " + (ukLearningProviderReferenceNumberHasError ? "govuk-input--error" : ""), @id = "UKLearningProviderReferenceNumber", @type = "text", spellcheck = "false", autocomplete = "off" }) -
-
- -
or
-
- - @Html.LabelFor(m => m.Other, new { @class = "govuk-label govuk-radios__label", @for = "Other" }) +
+ + @Html.LabelFor(m => m.UKLearningProviderReference, new { @class = "govuk-label govuk-radios__label", @for = "VAT" }) +
+
+
+ @Html.LabelFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-label", @for = Model.UKLearningProviderReferenceNumber }) + @Html.ValidationMessageFor(m => m.UKLearningProviderReferenceNumber, "", new { @class = "govuk-error-message", @id = "UKLearningProviderReferenceNumber-error" }) + @Html.TextBoxFor(m => m.UKLearningProviderReferenceNumber, new { @class = "govuk-input " + (ukLearningProviderReferenceNumberHasError ? "govuk-input--error" : ""), @id = "UKLearningProviderReferenceNumber", @type = "text", spellcheck = "false", autocomplete = "off" })
-
-
- @StaticTextResource.Global_Continue - -
+ +
or
+
+ + @Html.LabelFor(m => m.Other, new { @class = "govuk-label govuk-radios__label", @for = "Other" }) +
+
+
+
+ @StaticTextResource.Global_Continue +
+
From 368eb61958820c207cee977f666eb86dde367d40 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 28 Nov 2024 13:17:32 +0000 Subject: [PATCH 04/46] added identifier description --- .../Constants/OrganisationSchemeType.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Frontend/CO.CDP.OrganisationApp/Constants/OrganisationSchemeType.cs b/Frontend/CO.CDP.OrganisationApp/Constants/OrganisationSchemeType.cs index 0955831dc..096880a85 100644 --- a/Frontend/CO.CDP.OrganisationApp/Constants/OrganisationSchemeType.cs +++ b/Frontend/CO.CDP.OrganisationApp/Constants/OrganisationSchemeType.cs @@ -41,6 +41,12 @@ public static class OrganisationSchemeType return null; OrganisationScheme.TryGetValue(scheme, out var value); + + if (string.IsNullOrEmpty(value)) + { + value = "Other / None"; + } + return value; } } From 704d8ba86faa23c6b8a561bb1da4f6b5d2240c7e Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Thu, 28 Nov 2024 14:04:41 +0000 Subject: [PATCH 05/46] Translations --- .../OrganisationDetailsSummary.cshtml.cs | 2 +- ...nisationInternationalIdentification.cshtml | 11 +- ...ationInternationalIdentification.cshtml.cs | 14 +-- ...nInternationalIdentificationCountry.cshtml | 2 +- ...ternationalIdentificationCountry.cshtml.cs | 6 +- .../RequiredIfAttribute.cs | 10 +- .../StaticTextResource.resx | 107 +++++++++--------- 7 files changed, 77 insertions(+), 75 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationDetailsSummary.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationDetailsSummary.cshtml.cs index 797fbf39a..925909600 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationDetailsSummary.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationDetailsSummary.cshtml.cs @@ -97,5 +97,5 @@ public async Task OnPost() roles: [details.OrganisationType!.Value.AsPartyRole()], personId: user.PersonId.Value ); - } + } } \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml index 0ad57513e..e76a45ce4 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml @@ -4,7 +4,7 @@ @using CO.CDP.Localization @{ - ViewData["Title"] = "Is your organisation on any of these registries?"; + ViewData["Title"] = @StaticTextResource.OrganisationRegistration_InternationalIdentifier_Heading; var backLink = $"{RegistrationStepModel.OrganisationInternationalIdentificationCountryPage}{(Request.Query.ContainsKey("frm-summary") ? "?frm-summary" : "")}"; @@ -60,11 +60,11 @@
- + @Html.LabelFor(m => m.RegistrationNumbers, htmlAttributes: new { @class = "govuk-label" }) @if (hasError) { - Error: + @StaticTextResource.Global_Error: @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage } @@ -97,11 +97,12 @@
- + @Html.LabelFor(m => m.RegistrationNumbers, htmlAttributes: new { @class = "govuk-label" }) + @if (ModelState[nameof(Model.RegistrationNumbers)]?.Errors?.Any() ?? false) { - Error: + @StaticTextResource.Global_Error: @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs index 9f6ab6ac4..af61a4323 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs @@ -6,9 +6,9 @@ using CO.CDP.OrganisationApp.Constants; using System.ComponentModel.DataAnnotations; using System.ComponentModel; -using CO.CDP.Mvc.Validation; using ApiException = CO.CDP.EntityVerificationClient.ApiException; - +using CO.CDP.Localization; +using CO.CDP.Mvc.Validation; namespace CO.CDP.OrganisationApp.Pages.Registration; @@ -27,13 +27,13 @@ public class OrganisationInternationalIdentificationModel(ISession session, public ICollection InternationalIdentifiers { get; set; } = new List(); [BindProperty] - [DisplayName("Organisation Type")] - [Required(ErrorMessage = "Select an option")] + [DisplayName(nameof(StaticTextResource.Organisation_International_Type_Heading))] + [Required(ErrorMessageResourceName = nameof(StaticTextResource.Organisation_International_Type_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] public string? OrganisationScheme { get; set; } [BindProperty] - [DisplayName("Registration Number")] - [RequiredIfHasValue(nameof(OrganisationScheme), ErrorMessage = "Enter the number")] + [DisplayName(nameof(StaticTextResource.Organisation_International_Registration_Number_Heading))] + [RequiredIfHasValue("OrganisationScheme", ErrorMessageResourceName = nameof(StaticTextResource.Organisation_International_Registration_Number_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] public Dictionary RegistrationNumbers { get; set; } = new Dictionary(); [BindProperty] @@ -43,7 +43,7 @@ public class OrganisationInternationalIdentificationModel(ISession session, public string? OrganisationName; - public FlashMessage NotificationBannerCompanyAlreadyRegistered { get { return new FlashMessage($"An organisation with this registration number already exists. Change the registration number or request to join {OrganisationName}."); } } + public FlashMessage NotificationBannerCompanyAlreadyRegistered { get { return new FlashMessage(string.Format(StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyAlreadyRegistered_NotificationBanner, Identifier, OrganisationName)); } } public async Task OnGet() { diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml index 6f391ed45..570d4c48f 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml @@ -4,7 +4,7 @@ @using CO.CDP.Localization @{ - ViewData["Title"] = "Select which country your organisation is registered"; + ViewData["Title"] = @StaticTextResource.OrganisationRegistration_InternationalCountry_Heading; var countryHasError = ModelState[nameof(Model.Country)]?.Errors?.Any() ?? false; var backLink = $"{RegistrationStepModel.OrganisationIdentifierPage}{(Request.Query.ContainsKey("frm-summary") ? "?frm-summary" : "")}"; diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs index 799659b4a..ed52a8583 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml.cs @@ -1,3 +1,4 @@ +using CO.CDP.Localization; using CO.CDP.OrganisationApp.Models; using Microsoft.AspNetCore.Mvc; using System.ComponentModel; @@ -12,8 +13,9 @@ public class OrganisationInternationalIdentificationCountryModel(ISession sessio public override string CurrentPage => OrganisationInternationalIdentificationCountryPage; [BindProperty] - [DisplayName("Select which country your organisation is registered")] - [Required(ErrorMessage = "Select a country")] + + [DisplayName(nameof(StaticTextResource.Organisation_International_Country_Heading))] + [Required(ErrorMessageResourceName = nameof(StaticTextResource.Organisation_International_Country_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] public string? Country { get; set; } = string.Empty; public void OnGet() diff --git a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs index b01829dbd..11c1c6472 100644 --- a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs +++ b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs @@ -38,20 +38,22 @@ public RequiredIfHasValueAttribute(string organisationSchemeProperty) var organisationSchemeProperty = model.GetType().GetProperty(_organisationSchemeProperty); var organisationSchemeValue = organisationSchemeProperty?.GetValue(model) as string; + var errorMessage = ErrorMessageResolver.GetErrorMessage(ErrorMessage, ErrorMessageResourceName, ErrorMessageResourceType); + if (value is Dictionary registrationNumbers) { if (!string.IsNullOrEmpty(organisationSchemeValue) && registrationNumbers.TryGetValue(organisationSchemeValue, out var registrationNumberValue)) { if (string.IsNullOrEmpty(registrationNumberValue)) - { - return new ValidationResult(ErrorMessage ?? "Enter the number."); + { + return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required"); } } } else if (!string.IsNullOrEmpty(organisationSchemeValue) && value == null) { - return new ValidationResult("Enter the number."); + return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required"); } return ValidationResult.Success; @@ -73,7 +75,7 @@ public class RequiredIfContainsAttribute(string dependentProperty, string contai // Check if value is null or empty when condition is met if (conditionMet && (value == null || (value is List str && str.Count == 0))) { - return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required."); + return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required"); } return ValidationResult.Success; diff --git a/Services/CO.CDP.Localization/StaticTextResource.resx b/Services/CO.CDP.Localization/StaticTextResource.resx index 96e7ce135..48a26792e 100644 --- a/Services/CO.CDP.Localization/StaticTextResource.resx +++ b/Services/CO.CDP.Localization/StaticTextResource.resx @@ -1,17 +1,17 @@  - @@ -141,7 +141,7 @@ Back - + Download @@ -285,9 +285,6 @@ My organisations - - Organisation name - Pending approval @@ -1708,15 +1705,6 @@ For example, 27 3 2007 - - Day - - - Month - - - Year - Upload a file @@ -1822,27 +1810,12 @@ Invalid country name '{0}' - - Yes - - - No - Save and continue Save - - Remove - - - Please select - - - Change - Back to supplier information @@ -2038,4 +2011,28 @@ These exclusions are defined in <a href="{0}" target="_blank">schedule 7 of the Procurement Act 2023 (opens in new tab)</a>. + + Select which country your organisation is registered + + + Select which country your organisation is registered + + + Select a country + + + Is your organisation on any of these registries? + + + Organisation Type + + + Select an option + + + Registration Number + + + Enter the number + \ No newline at end of file From b57c16f7eb2c0984d627d089b05c1e87efdf19e8 Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Fri, 29 Nov 2024 12:40:38 +0000 Subject: [PATCH 06/46] added changes as per code review --- .../CO.CDP.OrganisationApp.csproj | 13 +----------- .../OrganisationIdentification.cshtml | 2 +- ...nisationInternationalIdentification.cshtml | 10 +++++----- ...ationInternationalIdentification.cshtml.cs | 10 +++++----- ...nInternationalIdentificationCountry.cshtml | 2 +- ...ternationalIdentificationCountry.cshtml.cs | 6 +++--- .../RequiredIfAttribute.cs | 12 +++++------ .../StaticTextResource.resx | 20 ++++++++++++------- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj index 76d0bb368..aa4a17889 100644 --- a/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj +++ b/Frontend/CO.CDP.OrganisationApp/CO.CDP.OrganisationApp.csproj @@ -27,17 +27,6 @@ - - - - - - - - - true - PreserveNewest - - + diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml index 586e3764e..4e8dea938 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml @@ -47,7 +47,7 @@

- Enter a non-UK registry and number + @StaticTextResource.Organisation_OrganisationIdentification_NonUk_Link

diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml index e76a45ce4..812e3cb16 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml @@ -35,7 +35,7 @@
- Select one then enter the registration number + @StaticTextResource.OrganisationRegistration_InternationalIdentifier_Select_Indentifier
@@ -64,8 +64,8 @@ @if (hasError) { - @StaticTextResource.Global_Error: - @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage + @StaticTextResource.Global_Error: + @Html.ValidationMessageFor(m => m.RegistrationNumbers) } - @StaticTextResource.Global_Error: - @ModelState[nameof(Model.RegistrationNumbers)]!.Errors[0].ErrorMessage + @StaticTextResource.Global_Error: + @Html.ValidationMessageFor(m => m.RegistrationNumbers) } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs index af61a4323..f6a39918c 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentification.cshtml.cs @@ -27,13 +27,13 @@ public class OrganisationInternationalIdentificationModel(ISession session, public ICollection InternationalIdentifiers { get; set; } = new List(); [BindProperty] - [DisplayName(nameof(StaticTextResource.Organisation_International_Type_Heading))] - [Required(ErrorMessageResourceName = nameof(StaticTextResource.Organisation_International_Type_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] + [DisplayName(nameof(StaticTextResource.OrganisationRegistration_InternationalIdentifier_Type_Heading))] + [Required(ErrorMessageResourceName = nameof(StaticTextResource.OrganisationRegistration_InternationalIdentifier_Type_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] public string? OrganisationScheme { get; set; } - [BindProperty] - [DisplayName(nameof(StaticTextResource.Organisation_International_Registration_Number_Heading))] - [RequiredIfHasValue("OrganisationScheme", ErrorMessageResourceName = nameof(StaticTextResource.Organisation_International_Registration_Number_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] + [BindProperty] + [DisplayName(nameof(StaticTextResource.OrganisationRegistration_InternationalIdentifier_RegistrationNumber_Heading))] + [RequiredIfHasValue("OrganisationScheme", ErrorMessageResourceName = nameof(StaticTextResource.OrganisationRegistration_InternationalIdentifier_RegistrationNumber_Required_ErrorMessage), ErrorMessageResourceType = typeof(StaticTextResource))] public Dictionary RegistrationNumbers { get; set; } = new Dictionary(); [BindProperty] diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml index 570d4c48f..3f3622e32 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationInternationalIdentificationCountry.cshtml @@ -41,7 +41,7 @@

} + aria-describedby="ca-type-item-hint" @IsSelected(StaticTextResource.SupplierToBuyer_OrganisationType_CentralGovernment_Short)>
@StaticTextResource.SupplierToBuyer_OrganisationType_CentralGovernment_Title: @@ -69,9 +69,9 @@
+ aria-describedby="ca-type-2-item-hint" @IsSelected(StaticTextResource.SupplierToBuyer_OrganisationType_RegionalAndLocalGovernment_Short)>
@StaticTextResource.SupplierToBuyer_OrganisationType_RegionalAndLocalGovernment_Title: @@ -88,27 +88,27 @@
+ type="radio" value="PublicUndertaking" aria-describedby="ca-type-3-item-hint" @IsSelected(StaticTextResource.SupplierToBuyer_OrganisationType_PublicUndertaking_Short)>
- @StaticTextResource.SupplierToBuyer_OrganisationType_PublicUndertaking + @StaticTextResource.SupplierToBuyer_OrganisationType_PublicUndertakingAuthority
+ type="radio" value="PrivateUtility" aria-describedby="ca-type-4-item-hint" @IsSelected(StaticTextResource.SupplierToBuyer_OrganisationType_PrivateUtility_Short)>
- @StaticTextResource.SupplierToBuyer_OrganisationType_PrivateUtility + @StaticTextResource.SupplierToBuyer_OrganisationType_PrivateUtility_Hint
+ type="radio" value="Other" data-aria-controls="conditional-ca-type-5" @IsSelected(StaticTextResource.SupplierToBuyer_OrganisationType_Other)> @@ -129,7 +129,7 @@ id="OtherValue" name="OtherValue" type="text" aria-describedby="ca-type-5-item-hint @(otherHasError ? "other-buyer-type-error" : "")" - value="@(Model.BuyerOrganisationType == "Other" ? Model.OtherValue : "")"> + value="@(Model.BuyerOrganisationType == StaticTextResource.SupplierToBuyer_OrganisationType_Other ? Model.OtherValue : "")">
diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationType.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationType.cshtml.cs index c7da44c69..16b10379f 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationType.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationType.cshtml.cs @@ -66,10 +66,10 @@ public IActionResult OnPost() public static Dictionary BuyerTypes => new() { - { "CentralGovernment", "Central government, public authority: UK, Scottish, Welsh and Northern Irish Executive"}, - { "RegionalAndLocalGovernment", "Regional and local government, public authority: UK, Scottish, Welsh and Northern Irish"}, - { "PublicUndertaking", "Public undertaking"}, - { "PrivateUtility", "Private utility"} + { StaticTextResource.SupplierToBuyer_OrganisationType_CentralGovernment_Short, StaticTextResource.SupplierToBuyer_OrganisationType_CentralGovernment}, + { StaticTextResource.SupplierToBuyer_OrganisationType_RegionalAndLocalGovernment_Short, StaticTextResource.SupplierToBuyer_OrganisationType_RegionalAndLocalGovernment}, + { StaticTextResource.SupplierToBuyer_OrganisationType_PublicUndertaking_Short, StaticTextResource.SupplierToBuyer_OrganisationType_PublicUndertaking}, + { StaticTextResource.SupplierToBuyer_OrganisationType_PrivateUtility_Short, StaticTextResource.SupplierToBuyer_OrganisationType_PrivateUtility} }; private void SupplierToBuyerStateUpdate() diff --git a/Services/CO.CDP.Localization/StaticTextResource.resx b/Services/CO.CDP.Localization/StaticTextResource.resx index 62f801a0f..fc119a041 100644 --- a/Services/CO.CDP.Localization/StaticTextResource.resx +++ b/Services/CO.CDP.Localization/StaticTextResource.resx @@ -2551,10 +2551,10 @@ Other - + For example, private companies that have been granted a special or exclusive right to provide utility activities to the public. Such as National Grid or British Gas. - + Unlike a public authority, organisations that operate commercially and provide utility activities to the public. For example, Transport for Wales. @@ -2602,4 +2602,28 @@ Others + + Central government, public authority: UK, Scottish, Welsh and Northern Irish Executive + + + CentralGovernment + + + Private utility + + + PrivateUtility + + + Public undertaking + + + PublicUndertaking + + + Regional and local government, public authority: UK, Scottish, Welsh and Northern Irish + + + RegionalAndLocalGovernment + \ No newline at end of file From f4de073df00cc8fc2b917d08e5a66967dbb5cd94 Mon Sep 17 00:00:00 2001 From: Jawwad Baig Date: Fri, 6 Dec 2024 01:07:18 +0000 Subject: [PATCH 29/46] #dp-911 rendering the change values as html.raw --- .../SupplierToBuyerOrganisationDetailsSummary.cshtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationDetailsSummary.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationDetailsSummary.cshtml index 45ffdd047..dcaf73eb4 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationDetailsSummary.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/SupplierToBuyerOrganisationDetailsSummary.cshtml @@ -46,7 +46,7 @@ }
- @StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeOrganisationType + @Html.Raw(@StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeOrganisationType)
@@ -58,7 +58,7 @@ @(details.Devolved == true ? StaticTextResource.Global_Yes : StaticTextResource.Global_No)
- @StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeDevolvedRegulations + @Html.Raw(@StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeDevolvedRegulations)
@if (details.Devolved == true) @@ -71,7 +71,7 @@ @Html.Raw(string.Join("
", details.Regulations.Select(x => x.Description())))
- @StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeDevolvedRegions + @Html.Raw(@StaticTextResource.SupplierToBuyer_OrganisationSummary_ChangeDevolvedRegions)
} From cf997504f7a62c4417158ee29c35c1010d79b9df Mon Sep 17 00:00:00 2001 From: Andy Mantell <134642+andymantell@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:50:51 +0000 Subject: [PATCH 30/46] Code tidyup in the flash message service --- .../FlashMessageService.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs b/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs index bcb354b4c..2fd204dee 100644 --- a/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs +++ b/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs @@ -8,26 +8,17 @@ public class FlashMessageService(ITempDataService tempDataService) : IFlashMessa { public void SetSuccessMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) { - var formattedHeading = FormatMessage(heading, urlParameters, htmlParameters); - var formattedDescription = description!= null ? FormatMessage(description, urlParameters, htmlParameters) : null; - var formattedTitle = title != null ? FormatMessage(title, urlParameters, htmlParameters) : null; - SetFlashMessage(FlashMessageTypes.Success, new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); + SetFlashMessage(FlashMessageTypes.Success, heading, description, title, urlParameters, htmlParameters); } public void SetImportantMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) { - var formattedHeading = FormatMessage(heading, urlParameters, htmlParameters); - var formattedDescription = description!= null ? FormatMessage(description, urlParameters, htmlParameters) : null; - var formattedTitle = title != null ? FormatMessage(title, urlParameters, htmlParameters) : null; - SetFlashMessage(FlashMessageTypes.Important, new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); + SetFlashMessage(FlashMessageTypes.Important, heading, description, title, urlParameters, htmlParameters); } public void SetFailureMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) { - var formattedHeading = FormatMessage(heading, urlParameters, htmlParameters); - var formattedDescription = description != null ? FormatMessage(description, urlParameters, htmlParameters) : null; - var formattedTitle = title != null ? FormatMessage(title, urlParameters, htmlParameters) : null; - SetFlashMessage(FlashMessageTypes.Failure, new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); + SetFlashMessage(FlashMessageTypes.Failure, heading, description, title, urlParameters, htmlParameters); } public FlashMessage? GetFlashMessage(string messageType) @@ -40,9 +31,13 @@ public void SetFailureMessage(string heading, string? description = null, string return tempDataService.Peek(messageType); } - private void SetFlashMessage(string messageType, FlashMessage message) + private void SetFlashMessage(string messageType, string heading, string? description, string? title, Dictionary? urlParameters, Dictionary? htmlParameters) { - tempDataService.Put(messageType, message); + var formattedHeading = FormatMessage(heading, urlParameters, htmlParameters); + var formattedDescription = description != null ? FormatMessage(description, urlParameters, htmlParameters) : null; + var formattedTitle = title != null ? FormatMessage(title, urlParameters, htmlParameters) : null; + + tempDataService.Put(messageType, new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); } private string FormatMessage(string format, Dictionary? urlParameters, Dictionary? htmlParameters) @@ -87,8 +82,13 @@ void SetImportantMessage( Dictionary? urlParameters = null, Dictionary? htmlParameters = null); + void SetFailureMessage(string heading, + string? description = null, + string? title = null, + Dictionary? urlParameters = null, + Dictionary? htmlParameters = null); + FlashMessage? GetFlashMessage(string messageType); FlashMessage? PeekFlashMessage(string messageType); - void SetFailureMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null); } From 96d810c20a799899920252aeb41e415cece2fb2d Mon Sep 17 00:00:00 2001 From: Shilpi Goel Date: Fri, 6 Dec 2024 10:17:04 +0000 Subject: [PATCH 31/46] Renamed ConditionMet --- Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs index 7b5bca7c1..cb8227b28 100644 --- a/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs +++ b/Libraries/CO.CDP.Mvc.Validation/RequiredIfAttribute.cs @@ -10,11 +10,11 @@ protected override ValidationResult IsValid(object? value, ValidationContext val var type = instance.GetType(); var propertyValue = type.GetProperty(dependentProperty)?.GetValue(instance, null); - bool conditionMet = (propertyValue?.Equals(targetValue) ?? false); + bool IsDependentMatchWithTarget = (propertyValue?.Equals(targetValue) ?? false); var errorMessage = ErrorMessageResolver.GetErrorMessage(ErrorMessage, ErrorMessageResourceName, ErrorMessageResourceType); - if (conditionMet && (value == null || (value is string str && string.IsNullOrWhiteSpace(str)))) + if (IsDependentMatchWithTarget && (value == null || (value is string str && string.IsNullOrWhiteSpace(str)))) { return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required"); } @@ -68,11 +68,11 @@ public class RequiredIfContainsAttribute(string dependentProperty, string contai var type = instance.GetType(); var propertyValue = type.GetProperty(dependentProperty)?.GetValue(instance, null); - bool conditionMet = propertyValue is List list && list.Contains(containsValue); + bool IsDependentMatchWithTarget = propertyValue is List list && list.Contains(containsValue); var errorMessage = ErrorMessageResolver.GetErrorMessage(ErrorMessage, ErrorMessageResourceName, ErrorMessageResourceType); - if (conditionMet && (value == null || (value is List str && str.Count == 0))) + if (IsDependentMatchWithTarget && (value == null || (value is List str && str.Count == 0))) { return new ValidationResult(errorMessage ?? $"{validationContext.DisplayName} is required"); } From 79a7ba54e56dcdbdbbf2736e97c4c0856efecf1e Mon Sep 17 00:00:00 2001 From: Andy Mantell <134642+andymantell@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:49:53 +0000 Subject: [PATCH 32/46] Simplify flash message service methods --- .../FlashMessageServiceTests.cs | 52 +++++++-------- .../Pages/ContactUsModelTests.cs | 3 +- ...rganisationRegisterBuyerAsSupplierTests.cs | 3 +- .../CompanyHouseNumberQuestionTests.cs | 6 +- .../Registration/JoinOrganisationTests.cs | 3 +- .../OrganisationIdentificationTests.cs | 6 +- .../Constants/FlashMessageTypes.cs | 8 --- .../FlashMessageService.cs | 65 +++++-------------- .../IFlashMessageService.cs | 18 +++++ .../Pages/ContactUs.cshtml.cs | 3 +- .../Pages/Cookies.cshtml.cs | 2 +- ...anisationRegisterBuyerAsSupplier.cshtml.cs | 3 +- .../CompanyHouseNumberQuestion.cshtml.cs | 5 +- .../Registration/JoinOrganisation.cshtml.cs | 2 +- .../OrganisationIdentification.cshtml.cs | 3 +- .../Pages/Shared/_FlashMessage.cshtml | 12 ++-- 16 files changed, 92 insertions(+), 102 deletions(-) delete mode 100644 Frontend/CO.CDP.OrganisationApp/Constants/FlashMessageTypes.cs create mode 100644 Frontend/CO.CDP.OrganisationApp/IFlashMessageService.cs diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/FlashMessageServiceTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/FlashMessageServiceTests.cs index bb585b48c..8065bfc8f 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/FlashMessageServiceTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/FlashMessageServiceTests.cs @@ -20,10 +20,10 @@ public void SetSuccessMessage_ShouldCallTempDataServiceWithSuccessMessageType() var heading = "Test success Heading"; var description = "Test success Description"; - _flashMessageService.SetSuccessMessage(heading, description); + _flashMessageService.SetFlashMessage(FlashMessageType.Success, heading, description); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Success, + s.Put("FlashMessage-" + FlashMessageType.Success.ToString(), It.Is(m => m.Heading == heading && m.Description == description)), Times.Once); } @@ -35,10 +35,10 @@ public void SetSuccessMessage_ShouldCallTempDataServiceWithTitle() var description = "Test success Description"; var title = "Test success Title"; - _flashMessageService.SetSuccessMessage(heading, description, title); + _flashMessageService.SetFlashMessage(FlashMessageType.Success, heading, description, title); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Success, + s.Put("FlashMessage-" + FlashMessageType.Success.ToString(), It.Is(m => m.Heading == heading && m.Description == description && m.Title == title)), Times.Once); } @@ -49,10 +49,10 @@ public void SetImportantMessage_ShouldCallTempDataServiceWithImportantMessageTyp var heading = "Test important Heading"; var description = "Test important Description"; - _flashMessageService.SetImportantMessage(heading, description); + _flashMessageService.SetFlashMessage(FlashMessageType.Important, heading, description); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Important, + s.Put("FlashMessage-" + FlashMessageType.Important.ToString(), It.Is(m => m.Heading == heading && m.Description == description)), Times.Once); } @@ -60,57 +60,57 @@ public void SetImportantMessage_ShouldCallTempDataServiceWithImportantMessageTyp [Fact] public void GetFlashMessage_ShouldReturnMessageFromTempDataService() { - var messageType = FlashMessageTypes.Success; + var messageType = FlashMessageType.Success; var expectedMessage = new FlashMessage("Test Heading", "Test Description"); - _tempDataServiceMock.Setup(s => s.Get(messageType)) + _tempDataServiceMock.Setup(s => s.Get("FlashMessage-" + messageType.ToString())) .Returns(expectedMessage); var result = _flashMessageService.GetFlashMessage(messageType); Assert.Equal(expectedMessage.Heading, result!.Heading); Assert.Equal(expectedMessage.Description, result.Description); - _tempDataServiceMock.Verify(s => s.Get(messageType), Times.Once); + _tempDataServiceMock.Verify(s => s.Get("FlashMessage-" + messageType.ToString()), Times.Once); } [Fact] public void PeekFlashMessage_ShouldReturnMessageFromTempDataServiceWithoutRemovingIt() { - var messageType = FlashMessageTypes.Important; + var messageType = FlashMessageType.Important; var expectedMessage = new FlashMessage("Test Heading", "Test Description"); - _tempDataServiceMock.Setup(s => s.Peek(messageType)) + _tempDataServiceMock.Setup(s => s.Peek("FlashMessage-" + messageType.ToString())) .Returns(expectedMessage); var result = _flashMessageService.PeekFlashMessage(messageType); Assert.Equal(expectedMessage.Heading, result!.Heading); Assert.Equal(expectedMessage.Description, result.Description); - _tempDataServiceMock.Verify(s => s.Peek(messageType), Times.Once); + _tempDataServiceMock.Verify(s => s.Peek("FlashMessage-" + messageType.ToString()), Times.Once); } [Fact] public void GetFlashMessage_ShouldReturnNull_WhenMessageDoesNotExist() { - var messageType = FlashMessageTypes.Success; - _tempDataServiceMock.Setup(s => s.Get(messageType)) + var messageType = FlashMessageType.Success; + _tempDataServiceMock.Setup(s => s.Get("FlashMessage-" + messageType.ToString())) .Returns((FlashMessage?)null); var result = _flashMessageService.GetFlashMessage(messageType); Assert.Null(result); - _tempDataServiceMock.Verify(s => s.Get(messageType), Times.Once); + _tempDataServiceMock.Verify(s => s.Get("FlashMessage-" + messageType.ToString()), Times.Once); } [Fact] public void PeekFlashMessage_ShouldReturnNull_WhenMessageDoesNotExist() { - var messageType = FlashMessageTypes.Important; - _tempDataServiceMock.Setup(s => s.Peek(messageType)) + var messageType = FlashMessageType.Important; + _tempDataServiceMock.Setup(s => s.Peek("FlashMessage-" + messageType.ToString())) .Returns((FlashMessage?)null); var result = _flashMessageService.PeekFlashMessage(messageType); Assert.Null(result); - _tempDataServiceMock.Verify(s => s.Peek(messageType), Times.Once); + _tempDataServiceMock.Verify(s => s.Peek("FlashMessage-" + messageType.ToString()), Times.Once); } [Fact] @@ -122,10 +122,10 @@ public void SetSuccessMessage_ShouldFormatHeadingAndDescriptionWithParameters() var expectedOutput = "Visit Test Organisation"; - _flashMessageService.SetSuccessMessage(formatString, formatString, null, urlParameters, htmlParameters); + _flashMessageService.SetFlashMessage(FlashMessageType.Success, formatString, formatString, null, urlParameters, htmlParameters); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Success, + s.Put("FlashMessage-" + FlashMessageType.Success.ToString(), It.Is(m => m.Heading == expectedOutput && m.Description == expectedOutput)), Times.Once); } @@ -138,10 +138,10 @@ public void SetImportantMessage_ShouldHandleNullDescriptionAndFormatHeading() var expectedHeading = "Access your account."; - _flashMessageService.SetImportantMessage(heading, null, null,urlParameters, null); + _flashMessageService.SetFlashMessage(FlashMessageType.Important, heading, null, null,urlParameters, null); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Important, + s.Put("FlashMessage-" + FlashMessageType.Important.ToString(), It.Is(m => m.Heading == expectedHeading && m.Description == null)), Times.Once); } @@ -155,10 +155,10 @@ public void SetImportantMessage_ShouldIgnoreUnusedPlaceholders() var expectedHeading = "Hello Alice"; - _flashMessageService.SetImportantMessage(heading, null, null, urlParameters, htmlParameters); + _flashMessageService.SetFlashMessage(FlashMessageType.Important, heading, null, null, urlParameters, htmlParameters); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Important, + s.Put("FlashMessage-" + FlashMessageType.Important.ToString(), It.Is(m => m.Heading == expectedHeading && m.Description == null)), Times.Once); } @@ -172,10 +172,10 @@ public void SetSuccessMessage_ShouldFormatNotBeVulnerabletoXSS() var expectedOutput = "Visit <script>alert("hello")</script>"; - _flashMessageService.SetSuccessMessage(formatString, formatString, formatString, urlParameters, htmlParameters); + _flashMessageService.SetFlashMessage(FlashMessageType.Success, formatString, formatString, formatString, urlParameters, htmlParameters); _tempDataServiceMock.Verify(s => - s.Put(FlashMessageTypes.Success, + s.Put("FlashMessage-" + FlashMessageType.Success.ToString(), It.Is(m => m.Heading == expectedOutput && m.Description == expectedOutput && m.Title == expectedOutput)), Times.Once); } diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/ContactUsModelTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/ContactUsModelTests.cs index ffd48ba14..0c2f49700 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/ContactUsModelTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/ContactUsModelTests.cs @@ -56,7 +56,8 @@ public async Task OnPost_FailedToSend_CallsTempDataService() result.Should().BeOfType(); - _mockFlashMessageService.Verify(api => api.SetFailureMessage( + _mockFlashMessageService.Verify(api => api.SetFlashMessage( + FlashMessageType.Failure, "There is a problem with the service", "Your message could not be sent. Try again or come back later.", "Failed to send", diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Organisation/OrganisationRegisterBuyerAsSupplierTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Organisation/OrganisationRegisterBuyerAsSupplierTests.cs index eb1cf5fee..96eb92bb6 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Organisation/OrganisationRegisterBuyerAsSupplierTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Organisation/OrganisationRegisterBuyerAsSupplierTests.cs @@ -37,7 +37,8 @@ public async Task ShouldUpdateOrganisation_WhenOrganisationIsNotYetATenderer() uo.Organisation.Roles.SequenceEqual(new[] { PartyRole.Tenderer }))), Times.Once); - flashMessageServiceMock.Verify(api => api.SetSuccessMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Success, "You have been registered as a supplier", It.IsAny(), null, diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/CompanyHouseNumberQuestionTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/CompanyHouseNumberQuestionTests.cs index 8457ed625..3a1858a2d 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/CompanyHouseNumberQuestionTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/CompanyHouseNumberQuestionTests.cs @@ -126,7 +126,8 @@ public async Task OnPost_WhenModelStateIsValidAndOrganisationAlreadyExists_Shoul Dictionary urlParameters = new() { ["organisationIdentifier"] = model.OrganisationIdentifier }; Dictionary htmlParameters = new() { ["organisationName"] = model.OrganisationName }; - flashMessageServiceMock.Verify(api => api.SetImportantMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Important, StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyAlreadyRegistered_NotificationBanner, null, null, @@ -160,7 +161,8 @@ public async Task OnPost_WhenModelStateIsValidAndCompanyNotFoundAtComapniesHouse var result = await model.OnPost(); - flashMessageServiceMock.Verify(api => api.SetImportantMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Important, StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyNotFound_NotificationBanner, null, null, diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/JoinOrganisationTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/JoinOrganisationTests.cs index d1121f2c9..512d98cfe 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/JoinOrganisationTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/JoinOrganisationTests.cs @@ -140,7 +140,8 @@ public async Task OnPost_CreateJoinRequestThrowsApiException_SetsFlashMessageAnd var result = await _joinOrganisationModel.OnPost(_identifier); - flashMessageServiceMock.Verify(api => api.SetImportantMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Important, ErrorMessagesList.AlreadyMemberOfOrganisation, null, null, diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationIdentificationTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationIdentificationTests.cs index f0602f2e2..115a92cdf 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationIdentificationTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Registration/OrganisationIdentificationTests.cs @@ -310,7 +310,8 @@ public async Task OnPost_WhenSchemeNotOtherAndOrganisationExistsInOganisationSer Dictionary urlParameters = new() { ["identifier"] = model.Identifier! }; Dictionary htmlParameters = new() { ["organisationName"] = model.OrganisationName! }; - flashMessageServiceMock.Verify(api => api.SetImportantMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Important, "An organisation with this registration number already exists. Change the registration number or request to join {organisationName}.", null, null, @@ -343,7 +344,8 @@ public async Task OnPost_WhenSchemeNotOtherAndIdentifierExistsInEntityVerificati Dictionary urlParameters = new() { ["identifier"] = model.Identifier! }; Dictionary htmlParameters = new() { ["organisationName"] = model.OrganisationName! }; - flashMessageServiceMock.Verify(api => api.SetImportantMessage( + flashMessageServiceMock.Verify(api => api.SetFlashMessage( + FlashMessageType.Important, "An organisation with this registration number already exists. Change the registration number or request to join {organisationName}.", null, null, diff --git a/Frontend/CO.CDP.OrganisationApp/Constants/FlashMessageTypes.cs b/Frontend/CO.CDP.OrganisationApp/Constants/FlashMessageTypes.cs deleted file mode 100644 index 5ce114b0b..000000000 --- a/Frontend/CO.CDP.OrganisationApp/Constants/FlashMessageTypes.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CO.CDP.OrganisationApp.Constants; - -public class FlashMessageTypes -{ - public const string Success = "FlashMessageSuccess"; - public const string Important = "FlashMessageImportant"; - public const string Failure = "FlashMessageFailure"; -} diff --git a/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs b/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs index 2fd204dee..61261d8f5 100644 --- a/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs +++ b/Frontend/CO.CDP.OrganisationApp/FlashMessageService.cs @@ -6,41 +6,31 @@ namespace CO.CDP.OrganisationApp; public class FlashMessageService(ITempDataService tempDataService) : IFlashMessageService { - public void SetSuccessMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) + public FlashMessage? GetFlashMessage(FlashMessageType messageType) { - SetFlashMessage(FlashMessageTypes.Success, heading, description, title, urlParameters, htmlParameters); + return tempDataService.Get(GetMessageKey(messageType)); } - public void SetImportantMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) + public FlashMessage? PeekFlashMessage(FlashMessageType messageType) { - SetFlashMessage(FlashMessageTypes.Important, heading, description, title, urlParameters, htmlParameters); + return tempDataService.Peek(GetMessageKey(messageType)); } - public void SetFailureMessage(string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) - { - SetFlashMessage(FlashMessageTypes.Failure, heading, description, title, urlParameters, htmlParameters); - } - - public FlashMessage? GetFlashMessage(string messageType) - { - return tempDataService.Get(messageType); - } - - public FlashMessage? PeekFlashMessage(string messageType) - { - return tempDataService.Peek(messageType); - } - - private void SetFlashMessage(string messageType, string heading, string? description, string? title, Dictionary? urlParameters, Dictionary? htmlParameters) + public void SetFlashMessage(FlashMessageType messageType, string heading, string? description = null, string? title = null, Dictionary? urlParameters = null, Dictionary? htmlParameters = null) { var formattedHeading = FormatMessage(heading, urlParameters, htmlParameters); var formattedDescription = description != null ? FormatMessage(description, urlParameters, htmlParameters) : null; var formattedTitle = title != null ? FormatMessage(title, urlParameters, htmlParameters) : null; - tempDataService.Put(messageType, new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); + tempDataService.Put(GetMessageKey(messageType), new FlashMessage(formattedHeading, formattedDescription, formattedTitle)); } - private string FormatMessage(string format, Dictionary? urlParameters, Dictionary? htmlParameters) + private static string GetMessageKey(FlashMessageType messageType) + { + return "FlashMessage-" + messageType.ToString(); + } + + private static string FormatMessage(string format, Dictionary? urlParameters, Dictionary? htmlParameters) { var encodedParameters = new Dictionary(); @@ -65,30 +55,9 @@ private string FormatMessage(string format, Dictionary? urlParam } } - -public interface IFlashMessageService +public enum FlashMessageType { - void SetSuccessMessage( - string heading, - string? description = null, - string? title = null, - Dictionary? urlParameters = null, - Dictionary? htmlParameters = null); - - void SetImportantMessage( - string heading, - string? description = null, - string? title = null, - Dictionary? urlParameters = null, - Dictionary? htmlParameters = null); - - void SetFailureMessage(string heading, - string? description = null, - string? title = null, - Dictionary? urlParameters = null, - Dictionary? htmlParameters = null); - - FlashMessage? GetFlashMessage(string messageType); - - FlashMessage? PeekFlashMessage(string messageType); -} + Success, + Important, + Failure +} \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/IFlashMessageService.cs b/Frontend/CO.CDP.OrganisationApp/IFlashMessageService.cs new file mode 100644 index 000000000..3008283a4 --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/IFlashMessageService.cs @@ -0,0 +1,18 @@ +using CO.CDP.OrganisationApp.Models; + +namespace CO.CDP.OrganisationApp; + +public interface IFlashMessageService +{ + void SetFlashMessage( + FlashMessageType messageType, + string heading, + string? description = null, + string? title = null, + Dictionary? urlParameters = null, + Dictionary? htmlParameters = null); + + FlashMessage? GetFlashMessage(FlashMessageType messageType); + + FlashMessage? PeekFlashMessage(FlashMessageType messageType); +} \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/ContactUs.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/ContactUs.cshtml.cs index c6512b4e2..68c810782 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/ContactUs.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/ContactUs.cshtml.cs @@ -58,7 +58,8 @@ public async Task OnPost() if (!success) { - flashMessageService.SetFailureMessage( + flashMessageService.SetFlashMessage( + FlashMessageType.Failure, heading: StaticTextResource.Supplementary_ContactUs_Failure_Heading, description: StaticTextResource.Supplementary_ContactUs_Failure_Description, title: StaticTextResource.Supplementary_ContactUs_Failure_Title diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Cookies.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Cookies.cshtml.cs index ea697bac2..7e49df3bc 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Cookies.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Cookies.cshtml.cs @@ -47,7 +47,7 @@ public IActionResult OnPost() { return LocalRedirect(QueryHelpers.AddQueryString(ReturnUrl, CookieSettings.CookiesAcceptedQueryString, "true")); } - flashMessageService.SetSuccessMessage("You’ve set your cookie preferences."); + flashMessageService.SetFlashMessage(FlashMessageType.Success, "You’ve set your cookie preferences."); return RedirectToPage("/Cookies"); } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/OrganisationRegisterBuyerAsSupplier.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/OrganisationRegisterBuyerAsSupplier.cshtml.cs index d4686b779..6db141e1b 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/OrganisationRegisterBuyerAsSupplier.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Organisation/OrganisationRegisterBuyerAsSupplier.cshtml.cs @@ -20,7 +20,8 @@ public async Task OnGet(Guid id) if (!orgInfo.Roles.Contains(PartyRole.Tenderer)) { await organisationClient.AddOrganisationRoles(id, [PartyRole.Tenderer]); - flashMessageService.SetSuccessMessage( + flashMessageService.SetFlashMessage( + FlashMessageType.Success, heading: "You have been registered as a supplier", description: $"You'll need to complete your supplier information to create sharecode." ); diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/CompanyHouseNumberQuestion.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/CompanyHouseNumberQuestion.cshtml.cs index 80ac66487..ad2fa6971 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/CompanyHouseNumberQuestion.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/CompanyHouseNumberQuestion.cshtml.cs @@ -65,7 +65,8 @@ public async Task OnPost() OrganisationName = organisation?.Name; if (organisation != null) { - flashMessageService.SetImportantMessage( + flashMessageService.SetFlashMessage( + FlashMessageType.Important, heading: StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyAlreadyRegistered_NotificationBanner, urlParameters: new() { ["organisationIdentifier"] = OrganisationIdentifier }, htmlParameters: new() { ["organisationName"] = organisation.Name } @@ -84,7 +85,7 @@ public async Task OnPost() { FailedCompaniesHouseNumber = CompaniesHouseNumber; - flashMessageService.SetImportantMessage(StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyNotFound_NotificationBanner); + flashMessageService.SetFlashMessage(FlashMessageType.Important, StaticTextResource.OrganisationRegistration_CompanyHouseNumberQuestion_CompanyNotFound_NotificationBanner); return Page(); } } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/JoinOrganisation.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/JoinOrganisation.cshtml.cs index 294ead8f3..4bb01e485 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/JoinOrganisation.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/JoinOrganisation.cshtml.cs @@ -54,7 +54,7 @@ await organisationClient.CreateJoinRequestAsync(OrganisationDetails.Id, } catch (ApiException) { - flashMessageService.SetImportantMessage(ErrorMessagesList.AlreadyMemberOfOrganisation); + flashMessageService.SetFlashMessage(FlashMessageType.Important, ErrorMessagesList.AlreadyMemberOfOrganisation); return Page(); } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml.cs index 5fbad766e..f4893d4ab 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Registration/OrganisationIdentification.cshtml.cs @@ -213,7 +213,8 @@ public async Task OnPost() if (OrganisationName != null) { - flashMessageService.SetImportantMessage( + flashMessageService.SetFlashMessage( + FlashMessageType.Important, heading: "An organisation with this registration number already exists. Change the registration number or request to join {organisationName}.", urlParameters: new() { ["identifier"] = Identifier }, htmlParameters: new() { ["organisationName"] = OrganisationName } diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Shared/_FlashMessage.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Shared/_FlashMessage.cshtml index f0daabb9e..ab482aa7c 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Shared/_FlashMessage.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Shared/_FlashMessage.cshtml @@ -3,9 +3,9 @@ @using CDP.OrganisationApp.Models @using Localization; -@if (flashMessageService.PeekFlashMessage(FlashMessageTypes.Success) != null) +@if (flashMessageService.PeekFlashMessage(FlashMessageType.Success) != null) { - var message = flashMessageService.GetFlashMessage(FlashMessageTypes.Success); + var message = flashMessageService.GetFlashMessage(FlashMessageType.Success); if(message != null) {