Skip to content

Commit

Permalink
Merge pull request #667 from bcgov/stories/ecer-3267
Browse files Browse the repository at this point in the history
Stories/ecer 3267
  • Loading branch information
farzadnadiri authored Nov 5, 2024
2 parents e9502a2 + 727ec2c commit c2b8f52
Show file tree
Hide file tree
Showing 19 changed files with 2,258 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
<p class="small font-weight-bold">{{ legalFirstName }}</p>
</v-col>
</v-row>
<v-row>
<v-col cols="4">
<p class="small">Previous name</p>
</v-col>
<v-col>
<p class="small font>weight-bold">{{ previousName }}</p>
</v-col>
</v-row>
<v-row>
<v-col cols="4">
<p class="small">Legal middle name</p>
Expand Down
14 changes: 9 additions & 5 deletions src/ECER.Managers.Admin.Contract/Metadatas/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ public record ProvincesQuery : IRequest<ProvincesQueryResults>
{
public string? ById { get; set; }
}
/// <summary>
/// Container for <see cref="ProvincesQuery"/> results
/// </summary>
/// <param name="Items">The </param>
public record ProvincesQueryResults(IEnumerable<Province> Items);
public record CountriesQuery : IRequest<CountriesQueryResults>
{
public string? ById { get; set; }
public string? ByCode { get; set; }
public string? ByName { get; set; }
}

public record ProvincesQueryResults(IEnumerable<Province> Items);
public record CountriesQueryResults(IEnumerable<Country> Items);
public record Province(string ProvinceId, string ProvinceName);
public record Country(string CountryId, string CountryName, string CountryCode);
11 changes: 10 additions & 1 deletion src/ECER.Managers.Admin/MetadataHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace ECER.Managers.Admin;
public class MetadataHandlers(
IMetadataResourceRepository metadataResourceRepository,
IMapper mapper
) : IRequestHandler<Contract.Metadatas.ProvincesQuery, ProvincesQueryResults>
) : IRequestHandler<Contract.Metadatas.ProvincesQuery, ProvincesQueryResults>,
IRequestHandler<Contract.Metadatas.CountriesQuery, CountriesQueryResults>
{
public async Task<ProvincesQueryResults> Handle(Contract.Metadatas.ProvincesQuery request, CancellationToken cancellationToken)
{
Expand All @@ -17,4 +18,12 @@ public async Task<ProvincesQueryResults> Handle(Contract.Metadatas.ProvincesQuer
var provinces = await metadataResourceRepository.QueryProvinces(new Resources.Documents.MetadataResources.ProvincesQuery() { ById = request.ById }, cancellationToken);
return new ProvincesQueryResults(mapper.Map<IEnumerable<Contract.Metadatas.Province>>(provinces)!);
}

public async Task<CountriesQueryResults> Handle(Contract.Metadatas.CountriesQuery request, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(request);

var countries = await metadataResourceRepository.QueryCountries(new Resources.Documents.MetadataResources.CountriesQuery() { ById = request.ById, ByCode = request.ByCode, ByName = request.ByName }, cancellationToken);
return new CountriesQueryResults(mapper.Map<IEnumerable<Contract.Metadatas.Country>>(countries)!);
}
}
1 change: 1 addition & 0 deletions src/ECER.Managers.Admin/MetadataMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ internal class MetadataMapper : Profile
public MetadataMapper()
{
CreateMap<Province, Contract.Metadatas.Province>();
CreateMap<Country, Contract.Metadatas.Country>();
}
}
13 changes: 8 additions & 5 deletions src/ECER.Managers.Registry/RegistrantHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using ECER.Managers.Registry.Contract.Registrants;
using ECER.Resources.Accounts.Registrants;
using ECER.Resources.Documents.Certifications;
using ECER.Resources.Documents.MetadataResources;
using MediatR;

namespace ECER.Managers.Registry;

/// <summary>
/// User Manager
/// </summary>
public class RegistrantHandlers(IRegistrantRepository registrantRepository, ICertificationRepository certificationRepository, IMapper mapper)
public class RegistrantHandlers(IRegistrantRepository registrantRepository, ICertificationRepository certificationRepository, IMetadataResourceRepository metadataResourceRepository, IMapper mapper)
: IRequestHandler<SearchRegistrantQuery, RegistrantQueryResults>,
IRequestHandler<RegisterNewUserCommand, string>,
IRequestHandler<UpdateRegistrantProfileCommand, string>
Expand Down Expand Up @@ -64,24 +65,27 @@ public async Task<string> Handle(RegisterNewUserCommand request, CancellationTok
ByRegistrationNumber = string.IsNullOrEmpty(request.Profile.RegistrationNumber) ? null : request.Profile.RegistrationNumber,
}, cancellationToken);

var countries = await metadataResourceRepository.QueryCountries(new CountriesQuery() { ByCode = request.Profile.ResidentialAddress!.Country }, cancellationToken);
var countryName = countries.First().CountryName;
request.Profile.ResidentialAddress = request.Profile.ResidentialAddress with { Country = countryName };
request.Profile.MailingAddress = request.Profile.ResidentialAddress;
var registrant = mapper.Map<Resources.Accounts.Registrants.Registrant>(request);

// Logic for the 'No' ECE case
if (string.IsNullOrEmpty(request.Profile.RegistrationNumber))
{
registrant.Profile.IsVerified = !registrants.Any();

return await registrantRepository.Create(registrant, cancellationToken);
}
// Logic for the 'Yes' ECE case
else
{
var matchedRegistrant = registrants.FirstOrDefault();

if (matchedRegistrant != null)
{
// Update the existing contact record
matchedRegistrant.Profile.IsVerified = true;
matchedRegistrant.Profile.ResidentialAddress = mapper.Map<Resources.Accounts.Registrants.Address>(request.Profile.ResidentialAddress);
matchedRegistrant.Profile.MailingAddress = mapper.Map<Resources.Accounts.Registrants.Address>(request.Profile.MailingAddress);
matchedRegistrant.Profile.Email = request.Profile.Email;
matchedRegistrant.Profile.FirstName = request.Profile.FirstName;
matchedRegistrant.Profile.LastName = request.Profile.LastName;
Expand All @@ -93,7 +97,6 @@ public async Task<string> Handle(RegisterNewUserCommand request, CancellationTok
}
else
{
// No matching contact, create a new record
registrant.Profile.IsVerified = false;
return await registrantRepository.Create(registrant, cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ECER.Managers.Registry/RegistrantMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class RegistrantMapper : AutoMapper.Profile
{
public RegistrantMapper()
{
CreateMap<Contract.Registrants.RegisterNewUserCommand, Resources.Accounts.Registrants.Registrant>()
CreateMap<Contract.Registrants.RegisterNewUserCommand, Registrant>()
.ForMember(d => d.Identities, opts => opts.MapFrom(s => (new[] { s.Identity })))
.ForMember(d => d.Profile, opts => opts.MapFrom(s => s.Profile))
.ForMember(d => d.Id, opts => opts.Ignore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
public interface IMetadataResourceRepository
{
Task<IEnumerable<Province>> QueryProvinces(ProvincesQuery query, CancellationToken cancellationToken);

Task<IEnumerable<Country>> QueryCountries(CountriesQuery query, CancellationToken cancellationToken);
}

public record Province(string ProvinceId, string ProvinceName);
public record Country(string CountryId, string CountryName, string CountryCode);
public record ProvincesQuery
{
public string? ById { get; set; }
}


public record CountriesQuery
{
public string? ById { get; set; }
public string? ByCode { get; set; }
public string? ByName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ public MetadataResourceRepository(EcerContext context, IMapper mapper)
this.mapper = mapper;
}

public async Task<IEnumerable<Country>> QueryCountries(CountriesQuery query, CancellationToken cancellationToken)
{
await Task.CompletedTask;
var countries = context.ecer_CountrySet;
if (query.ById != null) countries = countries.Where(r => r.ecer_CountryId == Guid.Parse(query.ById));
if (query.ByCode != null) countries = countries.Where(r => r.ecer_ShortName == query.ByCode);
if (query.ByName != null) countries = countries.Where(r => r.ecer_Name == query.ByName);

return mapper.Map<IEnumerable<Country>>(countries)!.ToList();
}

public async Task<IEnumerable<Province>> QueryProvinces(ProvincesQuery query, CancellationToken cancellationToken)
{
await Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AutoMapper;
using ECER.Utilities.DataverseSdk.Model;


namespace ECER.Resources.Documents.MetadataResources;

internal class MetadataResourceRepositoryMapper : Profile
Expand All @@ -12,5 +11,11 @@ public MetadataResourceRepositoryMapper()
.ForCtorParam(nameof(Province.ProvinceId), opt => opt.MapFrom(src => src.ecer_ProvinceId))
.ForCtorParam(nameof(Province.ProvinceName), opt => opt.MapFrom(src => src.ecer_Name))
.ValidateMemberList(MemberList.Destination);

CreateMap<ecer_Country, Country>(MemberList.Source)
.ForCtorParam(nameof(Country.CountryId), opt => opt.MapFrom(src => src.ecer_CountryId))
.ForCtorParam(nameof(Country.CountryName), opt => opt.MapFrom(src => src.ecer_Name))
.ForCtorParam(nameof(Country.CountryCode), opt => opt.MapFrom(src => src.ecer_ShortName))
.ValidateMemberList(MemberList.Destination);
}
}
22 changes: 22 additions & 0 deletions src/ECER.Utilities.DataverseSdk/Model/EcerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ public System.Linq.IQueryable<ECER.Utilities.DataverseSdk.Model.ecer_Certificate
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary"/> entities.
/// </summary>
public System.Linq.IQueryable<ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary> ecer_CertificateSummarySet
{
get
{
return this.CreateQuery<ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary>();
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="ECER.Utilities.DataverseSdk.Model.ecer_CertificateType"/> entities.
/// </summary>
Expand Down Expand Up @@ -887,6 +898,17 @@ public System.Linq.IQueryable<ECER.Utilities.DataverseSdk.Model.ecer_PSPSiteVisi
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement"/> entities.
/// </summary>
public System.Linq.IQueryable<ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement> ecer_recordmanagementSet
{
get
{
return this.CreateQuery<ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement>();
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="ECER.Utilities.DataverseSdk.Model.ecer_RenewalAssessment"/> entities.
/// </summary>
Expand Down
107 changes: 107 additions & 0 deletions src/ECER.Utilities.DataverseSdk/Model/Entities/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ public partial class Fields
public const string ecer_applicationassessment_ApplicantId = "ecer_applicationassessment_ApplicantId";
public const string ecer_certificate_Registrantid = "ecer_certificate_Registrantid";
public const string ecer_certificateconditions_Registrantid = "ecer_certificateconditions_Registrantid";
public const string ecer_certificatesummary_RegistrantId = "ecer_certificatesummary_RegistrantId";
public const string ecer_CertificationLevel = "ecer_certificationlevel";
public const string ecer_certifiedlevel_RegistrantId = "ecer_certifiedlevel_RegistrantId";
public const string ecer_changeofinformation_Contactid = "ecer_changeofinformation_Contactid";
Expand All @@ -675,21 +676,26 @@ public partial class Fields
public const string ecer_Contact_Contact_ecer_licensing_officers = "ecer_Contact_Contact_ecer_licensing_officers";
public const string ecer_contact_ecer_authentication_455 = "ecer_contact_ecer_authentication_455";
public const string ecer_contact_ecer_communication_122 = "ecer_contact_ecer_communication_122";
public const string ecer_contact_ecer_historicaldecision_contact = "ecer_contact_ecer_historicaldecision_contact";
public const string ecer_contact_ecer_investigation_Applicant = "ecer_contact_ecer_investigation_Applicant";
public const string ecer_contact_ecer_portaluser_474 = "ecer_contact_ecer_portaluser_474";
public const string ecer_contact_ecer_previousaddress_251 = "ecer_contact_ecer_previousaddress_251";
public const string ecer_contact_ecer_previousaddress_legacycontactid = "ecer_contact_ecer_previousaddress_legacycontactid";
public const string ecer_contact_ecer_recordmanagement_contact = "ecer_contact_ecer_recordmanagement_contact";
public const string ecer_contact_representedpsiid_ecer_postsecondaryinstitute = "ecer_contact_representedpsiid_ecer_postsecondaryinstitute";
public const string ecer_DateCertificateCancelled = "ecer_datecertificatecancelled";
public const string ecer_DateCertificateSuspended = "ecer_datecertificatesuspended";
public const string ecer_DateWEExtracted = "ecer_dateweextracted";
public const string ecer_eceprogramrepresentative_ContactId_contac = "ecer_eceprogramrepresentative_ContactId_contac";
public const string ecer_ecer_characterreference_Applicantid_conta = "ecer_ecer_characterreference_Applicantid_conta";
public const string ecer_ecer_professionaldevelopment_Applicantid_ = "ecer_ecer_professionaldevelopment_Applicantid_";
public const string ecer_ecer_workexperienceref_ReferenceContactid = "ecer_ecer_workexperienceref_ReferenceContactid";
public const string ecer_educationassessment_ApplicantId = "ecer_educationassessment_ApplicantId";
public const string ecer_guardianreference_Applicantid = "ecer_guardianreference_Applicantid";
public const string ecer_HasCertificate = "ecer_hascertificate";
public const string ecer_HasCertificateCancelled = "ecer_hascertificatecancelled";
public const string ecer_hascertificatecancelledName = "ecer_hascertificatecancelledname";
public const string ecer_hascertificateName = "ecer_hascertificatename";
public const string ecer_HasCertificateSuspended = "ecer_hascertificatesuspended";
public const string ecer_hascertificatesuspendedName = "ecer_hascertificatesuspendedname";
public const string ecer_HasCurrentCertificateConditions = "ecer_hascurrentcertificateconditions";
Expand Down Expand Up @@ -4133,6 +4139,36 @@ public System.Nullable<System.DateTime> ecer_DateCertificateSuspended
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("ecer_dateweextracted")]
public System.Nullable<System.DateTime> ecer_DateWEExtracted
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetAttributeValue<System.Nullable<System.DateTime>>("ecer_dateweextracted");
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.SetAttributeValue("ecer_dateweextracted", value);
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("ecer_hascertificate")]
public System.Nullable<bool> ecer_HasCertificate
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetAttributeValue<System.Nullable<bool>>("ecer_hascertificate");
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.SetAttributeValue("ecer_hascertificate", value);
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("ecer_hascertificatecancelled")]
public System.Nullable<bool> ecer_HasCertificateCancelled
{
Expand Down Expand Up @@ -4165,6 +4201,23 @@ public string ecer_hascertificatecancelledName
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("ecer_hascertificatename")]
public string ecer_hascertificateName
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
if (this.FormattedValues.Contains("ecer_hascertificate"))
{
return this.FormattedValues["ecer_hascertificate"];
}
else
{
return default(string);
}
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("ecer_hascertificatesuspended")]
public System.Nullable<bool> ecer_HasCertificateSuspended
{
Expand Down Expand Up @@ -7327,6 +7380,24 @@ public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.
}
}

/// <summary>
/// 1:N ecer_certificatesummary_RegistrantId
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("ecer_certificatesummary_RegistrantId")]
public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary> ecer_certificatesummary_RegistrantId
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary>("ecer_certificatesummary_RegistrantId", null);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.SetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_CertificateSummary>("ecer_certificatesummary_RegistrantId", null, value);
}
}

/// <summary>
/// 1:N ecer_certifiedlevel_RegistrantId
/// </summary>
Expand Down Expand Up @@ -7489,6 +7560,24 @@ public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.
}
}

/// <summary>
/// 1:N ecer_contact_ecer_historicaldecision_contact
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("ecer_contact_ecer_historicaldecision_contact")]
public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.ecer_HistoricalDecision> ecer_contact_ecer_historicaldecision_contact
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_HistoricalDecision>("ecer_contact_ecer_historicaldecision_contact", null);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.SetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_HistoricalDecision>("ecer_contact_ecer_historicaldecision_contact", null, value);
}
}

/// <summary>
/// 1:N ecer_contact_ecer_investigation_Applicant
/// </summary>
Expand Down Expand Up @@ -7561,6 +7650,24 @@ public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.
}
}

/// <summary>
/// 1:N ecer_contact_ecer_recordmanagement_contact
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("ecer_contact_ecer_recordmanagement_contact")]
public System.Collections.Generic.IEnumerable<ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement> ecer_contact_ecer_recordmanagement_contact
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement>("ecer_contact_ecer_recordmanagement_contact", null);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.SetRelatedEntities<ECER.Utilities.DataverseSdk.Model.ecer_recordmanagement>("ecer_contact_ecer_recordmanagement_contact", null, value);
}
}

/// <summary>
/// 1:N ecer_eceprogramrepresentative_ContactId_contac
/// </summary>
Expand Down
Loading

0 comments on commit c2b8f52

Please sign in to comment.