From 53162582eca4ccf08d9fd2bf8e51f0baeeadeda3 Mon Sep 17 00:00:00 2001 From: Peggy Date: Wed, 4 Dec 2024 07:32:08 -0800 Subject: [PATCH] [SPDBT-3352] Licensing - Create Controlling Member CRC shell Application when No Email is provided (#1962) # Description This PR includes the following proposed change(s): - [SPDBT-3352] Licensing - Create Controlling Member CRC shell Application when No Email is provided - Backend --- src/Spd.Manager.Licence/BizMemberContract.cs | 3 +- src/Spd.Manager.Licence/BizMemberManager.cs | 48 ++++++++++++++----- src/Spd.Manager.Licence/Mappings.cs | 7 +++ .../Contract.cs | 6 +-- .../Mappings.cs | 3 +- .../SharedMappingFuncs.cs | 2 +- 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/Spd.Manager.Licence/BizMemberContract.cs b/src/Spd.Manager.Licence/BizMemberContract.cs index baa159a4d..d5453dfdc 100644 --- a/src/Spd.Manager.Licence/BizMemberContract.cs +++ b/src/Spd.Manager.Licence/BizMemberContract.cs @@ -68,5 +68,6 @@ public record ControllingMemberAppInviteVerifyResponse() public enum ControllingMemberAppInviteTypeCode { New, - Update + Update, + CreateShellApp } \ No newline at end of file diff --git a/src/Spd.Manager.Licence/BizMemberManager.cs b/src/Spd.Manager.Licence/BizMemberManager.cs index f25e3c199..f69ed1edc 100644 --- a/src/Spd.Manager.Licence/BizMemberManager.cs +++ b/src/Spd.Manager.Licence/BizMemberManager.cs @@ -5,6 +5,7 @@ using Spd.Resource.Repository.Biz; using Spd.Resource.Repository.BizContact; using Spd.Resource.Repository.BizLicApplication; +using Spd.Resource.Repository.ControllingMemberCrcApplication; using Spd.Resource.Repository.ControllingMemberInvite; using Spd.Resource.Repository.Document; using Spd.Resource.Repository.LicApp; @@ -37,6 +38,7 @@ internal class BizMemberManager : private readonly IBizRepository _bizRepository; private readonly IPersonLicApplicationRepository _personLicApplicationRepository; private readonly IControllingMemberInviteRepository _cmInviteRepository; + private readonly IControllingMemberCrcRepository _cmCrcRepository; public BizMemberManager( ILicenceRepository licenceRepository, @@ -47,7 +49,8 @@ public BizMemberManager( IMainFileStorageService mainFileStorageService, ITransientFileStorageService transientFileStorageService, IBizContactRepository bizContactRepository, - IControllingMemberInviteRepository cmInviteRepository) + IControllingMemberInviteRepository cmInviteRepository, + IControllingMemberCrcRepository cmCrcRepository) : base(mapper, documentUrlRepository, feeRepository, @@ -58,6 +61,7 @@ public BizMemberManager( { _bizContactRepository = bizContactRepository; _cmInviteRepository = cmInviteRepository; + _cmCrcRepository = cmCrcRepository; } public async Task Handle(VerifyBizControllingMemberInviteCommand cmd, CancellationToken cancellationToken) @@ -108,18 +112,40 @@ public async Task Handle(BizControllingM throw new ApiException(HttpStatusCode.BadRequest, "Cannot find the non-swl controlling member."); if (contactResp.BizContactRoleCode != BizContactRoleEnum.ControllingMember) throw new ApiException(HttpStatusCode.BadRequest, "Cannot send out invitation for non-swl controlling member."); - if (string.IsNullOrWhiteSpace(contactResp.EmailAddress)) + if (cmd.InviteTypeCode != ControllingMemberAppInviteTypeCode.CreateShellApp && string.IsNullOrWhiteSpace(contactResp.EmailAddress)) throw new ApiException(HttpStatusCode.BadRequest, "Cannot send out invitation when there is no email address provided."); - //if (contactResp.LatestControllingMemberCrcAppPortalStatusEnum != null && - // contactResp.LatestControllingMemberCrcAppPortalStatusEnum != ApplicationPortalStatusEnum.CompletedCleared) - // throw new ApiException(HttpStatusCode.BadRequest, "This business contact already has a CRC application"); - - var createCmd = _mapper.Map(contactResp); - createCmd.CreatedByUserId = cmd.UserId; - createCmd.HostUrl = cmd.HostUrl; - createCmd.InviteTypeCode = Enum.Parse(cmd.InviteTypeCode.ToString()); - await _cmInviteRepository.ManageAsync(createCmd, cancellationToken); + if (cmd.InviteTypeCode == ControllingMemberAppInviteTypeCode.CreateShellApp) + { + var createShellApp = _mapper.Map(contactResp); + //get biz app id + IEnumerable list = await _licAppRepository.QueryAsync( + new LicenceAppQuery( + null, + contactResp.BizId, + new List { ServiceTypeEnum.SecurityBusinessLicence }, + new List + { + ApplicationPortalStatusEnum.Draft, + ApplicationPortalStatusEnum.Incomplete, + ApplicationPortalStatusEnum.VerifyIdentity, + ApplicationPortalStatusEnum.AwaitingPayment + }), + cancellationToken); + LicenceAppListResp? app = list.Where(a => a.ApplicationTypeCode != ApplicationTypeEnum.Replacement) + .OrderByDescending(a => a.CreatedOn) + .FirstOrDefault(); + createShellApp.ParentBizLicApplicationId = app?.LicenceAppId; + await _cmCrcRepository.CreateControllingMemberCrcApplicationAsync(createShellApp, cancellationToken); + } + else + { + var createCmd = _mapper.Map(contactResp); + createCmd.CreatedByUserId = cmd.UserId; + createCmd.HostUrl = cmd.HostUrl; + createCmd.InviteTypeCode = Enum.Parse(cmd.InviteTypeCode.ToString()); + await _cmInviteRepository.ManageAsync(createCmd, cancellationToken); + } return new ControllingMemberInvitesCreateResponse(cmd.BizContactId) { CreateSuccess = true }; } diff --git a/src/Spd.Manager.Licence/Mappings.cs b/src/Spd.Manager.Licence/Mappings.cs index 7ec15261c..a4c5108c9 100644 --- a/src/Spd.Manager.Licence/Mappings.cs +++ b/src/Spd.Manager.Licence/Mappings.cs @@ -413,6 +413,13 @@ public Mappings() .IncludeBase() .ForMember(d => d.HostUrl, opt => opt.Ignore()); + //this mapping is used for create shell app for no-email bizContact + CreateMap() + .ForMember(d => d.ServiceTypeCode, opt => opt.MapFrom(s => ServiceTypeEnum.SECURITY_BUSINESS_LICENCE_CONTROLLING_MEMBER_CRC)) + .ForMember(d => d.ApplicationTypeCode, opt => opt.MapFrom(s => ApplicationTypeEnum.New)) + .ForMember(d => d.ApplicationOriginTypeCode, opt => opt.MapFrom(_ => (ApplicationOriginTypeEnum?)null)) + .ForMember(d => d.AgreeToCompleteAndAccurate, opt => opt.MapFrom(s => false)); + CreateMap() .ForMember(d => d.InviteId, opt => opt.Ignore()) .ForMember(d => d.BizContactId, opt => opt.Ignore()) diff --git a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Contract.cs b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Contract.cs index c9ef9dbe5..1341c4bb9 100644 --- a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Contract.cs +++ b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Contract.cs @@ -21,12 +21,12 @@ public record ControllingMemberCrcApplication public string? MiddleName2 { get; set; } public string? Surname { get; set; } public bool? AgreeToCompleteAndAccurate { get; set; } - public DateOnly DateOfBirth { get; set; } + public DateOnly DateOfBirth { get; set; } = new DateOnly(1800, 1, 1); public GenderEnum? GenderCode { get; set; } public string? PhoneNumber { get; set; } public string? EmailAddress { get; set; } public bool? HasPreviousName { get; set; } - public IEnumerable Aliases { get; set; } + public IEnumerable Aliases { get; set; } = Array.Empty(); public bool? HasBcDriversLicence { get; set; } public string? BcDriversLicenceNumber { get; set; } public bool? IsPoliceOrPeaceOfficer { get; set; } @@ -39,7 +39,7 @@ public record ControllingMemberCrcApplication public string? BankruptcyHistoryDetail { get; set; } public bool? IsTreatedForMHC { get; set; } public ResidentialAddr? ResidentialAddressData { get; set; } - public IEnumerable? UploadedDocumentEnums { get; set; } + public IEnumerable? UploadedDocumentEnums { get; set; } = Array.Empty(); public Guid BizContactId { get; set; } } public record CreateControllingMemberCrcAppCmd() : ControllingMemberCrcApplication diff --git a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs index 7d4f3fcbf..4bb2e405f 100644 --- a/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs +++ b/src/Spd.Resource.Repository/ControllingMemberCrcApplication/Mappings.cs @@ -60,7 +60,7 @@ public Mappings() .ForMember(d => d.spd_lastname, opt => opt.MapFrom(s => s.Surname)) .ForMember(d => d.spd_middlename1, opt => opt.MapFrom(s => s.MiddleName1)) .ForMember(d => d.spd_middlename2, opt => opt.MapFrom(s => s.MiddleName2)) - .ForMember(d => d.spd_origin, opt => opt.MapFrom(s => (int)SharedMappingFuncs.GetOptionset(s.ApplicationOriginTypeCode))) + .ForMember(d => d.spd_origin, opt => opt.MapFrom(s => (int?)SharedMappingFuncs.GetOptionset(s.ApplicationOriginTypeCode))) .ForMember(d => d.spd_payer, opt => opt.MapFrom(s => (int)PayerPreferenceOptionSet.Organization)) .ForMember(d => d.spd_dateofbirth, opt => opt.MapFrom(s => SharedMappingFuncs.GetDateFromDateOnly(s.DateOfBirth))) .ForMember(d => d.spd_sex, opt => opt.MapFrom(s => SharedMappingFuncs.GetGender(s.GenderCode))) @@ -85,6 +85,7 @@ public Mappings() .ForMember(d => d.spd_hasdriverslicence, opt => opt.MapFrom(s => SharedMappingFuncs.GetYesNo(s.HasBcDriversLicence))) .ForMember(d => d.statecode, opt => opt.MapFrom(s => DynamicsConstants.StateCode_Active)) .ForMember(d => d.spd_submittedon, opt => opt.Ignore()) + .ForMember(d => d.spd_licencefee, opt => opt.MapFrom(s => 0)) .ForMember(d => d.spd_declaration, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate)) .ForMember(d => d.spd_declarationdate, opt => opt.MapFrom(s => SharedMappingFuncs.GetDeclarationDate(s.AgreeToCompleteAndAccurate))) .ForMember(d => d.spd_consent, opt => opt.MapFrom(s => s.AgreeToCompleteAndAccurate)) diff --git a/src/Spd.Resource.Repository/SharedMappingFuncs.cs b/src/Spd.Resource.Repository/SharedMappingFuncs.cs index a0cc3b53a..a0938fbd4 100644 --- a/src/Spd.Resource.Repository/SharedMappingFuncs.cs +++ b/src/Spd.Resource.Repository/SharedMappingFuncs.cs @@ -227,7 +227,7 @@ internal static IEnumerable GetUploadedDocumentEnums(strin } internal static bool GetIdentityConfirmed(ApplicationOriginTypeEnum? origin, ApplicationTypeEnum type) { - bool isNotPortal = origin != ApplicationOriginTypeEnum.Portal; + bool isNotPortal = origin == null || origin != ApplicationOriginTypeEnum.Portal; bool isNewOrRenewal = type == ApplicationTypeEnum.New || type == ApplicationTypeEnum.Renewal;