From 66a36ac75abdb5095add2c8d33c8cd8b96ae8bb9 Mon Sep 17 00:00:00 2001 From: peggy Date: Thu, 25 Jan 2024 10:52:07 -0800 Subject: [PATCH 1/6] temp --- .../PersonalLicenceAppContract.cs | 7 +++ .../PersonalLicenceAppManager.cs | 52 +++++++++++++++++++ .../Controllers/WorkerLicensingController.cs | 6 +++ 3 files changed, 65 insertions(+) diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppContract.cs b/src/Spd.Manager.Licence/PersonalLicenceAppContract.cs index 0d6489010..7e9539812 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppContract.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppContract.cs @@ -15,6 +15,7 @@ public interface IPersonalLicenceAppManager public Task Handle(AnonymousWorkerLicenceAppNewCommand command, CancellationToken ct); public Task Handle(AnonymousWorkerLicenceAppReplaceCommand command, CancellationToken ct); public Task Handle(AnonymousWorkerLicenceAppRenewCommand command, CancellationToken ct); + public Task Handle(AnonymousWorkerLicenceAppUpdateCommand command, CancellationToken ct); public Task> Handle(CreateDocumentInCacheCommand command, CancellationToken ct); } @@ -42,6 +43,11 @@ public record AnonymousWorkerLicenceAppRenewCommand( Guid KeyCode) : IRequest; +public record AnonymousWorkerLicenceAppUpdateCommand( + WorkerLicenceAppAnonymousSubmitRequestJson LicenceAnonymousRequest, + Guid KeyCode) + : IRequest; + public record GetWorkerLicenceQuery(Guid LicenceApplicationId) : IRequest; public record GetWorkerLicenceAppListQuery(Guid ApplicantId) : IRequest>; @@ -184,6 +190,7 @@ public record WorkerLicenceAppAnonymousSubmitRequestJson : WorkerLicenceAppBase public Guid[]? PreviousDocumentIds { get; set; } //documentUrlId, used for renew public Guid? OriginalApplicationId { get; set; } //for new, it should be null. for renew, replace, update, it should be original application id. public Guid? OriginalLicenceId { get; set; } //for new, it should be null. for renew, replace, update, it should be original licence id. + public bool? Reprint { get; set; } } public record WorkerLicenceCreateResponse diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index 3387579c4..5ec8fb205 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -312,6 +312,58 @@ await _documentRepository.ManageAsync( return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId }; } + + public async Task Handle(AnonymousWorkerLicenceAppUpdateCommand cmd, CancellationToken ct) + { + WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest; + if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Update) + throw new ArgumentException("should be a update request"); + + //validation: check if original licence meet replacement condition. + LicenceListResp originalLicences = await _licenceRepository.QueryAsync(new LicenceQry() { LicenceId = request.OriginalLicenceId }, ct); + if (originalLicences == null || !originalLicences.Items.Any()) + throw new ArgumentException("cannot find the licence that needs to be renewed."); + LicenceResp originalLic = originalLicences.Items.First(); + if (DateTime.UtcNow > originalLic.ExpiryDate.AddDays(Constants.LICENCE_RENEW_VALID_BEFORE_EXPIRATION_IN_DAYS).ToDateTime(new TimeOnly(0, 0)) + && DateTime.UtcNow < originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + throw new ArgumentException("the licence can only be renewed within 90 days of the expiry date."); + + CreateLicenceApplicationCmd createApp = _mapper.Map(request); + var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct); + + //add all new files user uploaded + if (cmd.LicenceAnonymousRequest.DocumentKeyCodes != null && cmd.LicenceAnonymousRequest.DocumentKeyCodes.Any()) + { + foreach (Guid fileKeyCode in cmd.LicenceAnonymousRequest.DocumentKeyCodes) + { + IEnumerable items = await _cache.Get>(fileKeyCode.ToString()); + foreach (LicAppFileInfo licAppFile in items) + { + DocumentTypeEnum? docType1 = GetDocumentType1Enum(licAppFile.LicenceDocumentTypeCode); + DocumentTypeEnum? docType2 = GetDocumentType2Enum(licAppFile.LicenceDocumentTypeCode); + DateOnly? expiredDate = cmd.LicenceAnonymousRequest? + .DocumentInfos? + .FirstOrDefault(d => d.LicenceDocumentTypeCode == licAppFile.LicenceDocumentTypeCode)? + .ExpiryDate; + //create bcgov_documenturl and file + await _documentRepository.ManageAsync(new CreateDocumentCmd + { + TempFile = _mapper.Map(licAppFile), + ApplicationId = response.LicenceAppId, + DocumentType = docType1, + DocumentType2 = docType2, + SubmittedByApplicantId = response.ContactId, + ExpiryDate = expiredDate, + }, ct); + } + } + } + + await CommitApplicationAsync(request, response.LicenceAppId, ct); + + return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId }; + } + #endregion private async Task CommitApplicationAsync(WorkerLicenceAppAnonymousSubmitRequestJson request, Guid licenceAppId, CancellationToken ct, bool HasSwl90DayLicence = false) diff --git a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs index 8763096b4..ca4598c18 100644 --- a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs @@ -327,6 +327,12 @@ public async Task SubmitSecurityWorkerLicenceApp AnonymousWorkerLicenceAppRenewCommand command = new(jsonRequest, keyCode); return await _mediator.Send(command); } + + if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Update) + { + AnonymousWorkerLicenceAppRenewCommand command = new(jsonRequest, keyCode); + return await _mediator.Send(command); + } return null; } #endregion From 85d350681b6ac1a5fb5deb5612ffeaea7ae9b8af Mon Sep 17 00:00:00 2001 From: peggy Date: Thu, 25 Jan 2024 15:57:48 -0800 Subject: [PATCH 2/6] temp --- src/Spd.Manager.Licence/Constants.cs | 1 + .../PersonalLicenceAppManager.cs | 76 +++++++++++-------- .../ServiceExtensions.cs | 2 + src/Spd.Resource.Applicants/Task/Contract.cs | 23 ++++++ src/Spd.Resource.Applicants/Task/Mappings.cs | 21 +++++ .../Task/TaskRepository.cs | 59 ++++++++++++++ 6 files changed, 152 insertions(+), 30 deletions(-) create mode 100644 src/Spd.Resource.Applicants/Task/Contract.cs create mode 100644 src/Spd.Resource.Applicants/Task/Mappings.cs create mode 100644 src/Spd.Resource.Applicants/Task/TaskRepository.cs diff --git a/src/Spd.Manager.Licence/Constants.cs b/src/Spd.Manager.Licence/Constants.cs index 583949205..0c1944f0e 100644 --- a/src/Spd.Manager.Licence/Constants.cs +++ b/src/Spd.Manager.Licence/Constants.cs @@ -3,4 +3,5 @@ internal class Constants { public static readonly int LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS = 14; public static readonly int LICENCE_RENEW_VALID_BEFORE_EXPIRATION_IN_DAYS = 90; + public static readonly int LICENCE_UPDATE_VALID_BEFORE_EXPIRATION_IN_DAYS = 14;//Licence holder can't request an update within 14 days of expiry date } diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index 5ec8fb205..5c29eda1b 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -1,5 +1,7 @@ using AutoMapper; using MediatR; +using Microsoft.AspNetCore.Http.HttpResults; +using Microsoft.Dynamics.CRM; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; using Spd.Resource.Applicants.Application; @@ -305,7 +307,7 @@ await _documentRepository.ManageAsync( } //todo: update all expiration date : for some doc type, some file got updated, some are still old files, and expiration data changed. - bool hasSwl90DayLicence = originalLic.LicenceTerm == LicenceTermEnum.NintyDays && + bool hasSwl90DayLicence = originalLic.LicenceTerm == LicenceTermEnum.NintyDays && originalLic.WorkerLicenceTypeCode == WorkerLicenceTypeEnum.SecurityWorkerLicence; await CommitApplicationAsync(request, response.LicenceAppId, ct, hasSwl90DayLicence); @@ -322,46 +324,60 @@ public async Task Handle(AnonymousWorkerLicenceA //validation: check if original licence meet replacement condition. LicenceListResp originalLicences = await _licenceRepository.QueryAsync(new LicenceQry() { LicenceId = request.OriginalLicenceId }, ct); if (originalLicences == null || !originalLicences.Items.Any()) - throw new ArgumentException("cannot find the licence that needs to be renewed."); + throw new ArgumentException("cannot find the licence that needs to be updated."); LicenceResp originalLic = originalLicences.Items.First(); - if (DateTime.UtcNow > originalLic.ExpiryDate.AddDays(Constants.LICENCE_RENEW_VALID_BEFORE_EXPIRATION_IN_DAYS).ToDateTime(new TimeOnly(0, 0)) - && DateTime.UtcNow < originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) - throw new ArgumentException("the licence can only be renewed within 90 days of the expiry date."); + if (DateTime.UtcNow.AddDays(Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS) > originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + throw new ArgumentException("can't request an update within 14 days of expiry date."); - CreateLicenceApplicationCmd createApp = _mapper.Map(request); - var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct); - - //add all new files user uploaded - if (cmd.LicenceAnonymousRequest.DocumentKeyCodes != null && cmd.LicenceAnonymousRequest.DocumentKeyCodes.Any()) + if ((request.Reprint != null && request.Reprint.Value) /*|| (CategoriesChanged or DogRestraint changed)*/) { - foreach (Guid fileKeyCode in cmd.LicenceAnonymousRequest.DocumentKeyCodes) + CreateLicenceApplicationCmd createApp = _mapper.Map(request); + var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct); + + //add all new files user uploaded + if (cmd.LicenceAnonymousRequest.DocumentKeyCodes != null && cmd.LicenceAnonymousRequest.DocumentKeyCodes.Any()) { - IEnumerable items = await _cache.Get>(fileKeyCode.ToString()); - foreach (LicAppFileInfo licAppFile in items) + foreach (Guid fileKeyCode in cmd.LicenceAnonymousRequest.DocumentKeyCodes) { - DocumentTypeEnum? docType1 = GetDocumentType1Enum(licAppFile.LicenceDocumentTypeCode); - DocumentTypeEnum? docType2 = GetDocumentType2Enum(licAppFile.LicenceDocumentTypeCode); - DateOnly? expiredDate = cmd.LicenceAnonymousRequest? - .DocumentInfos? - .FirstOrDefault(d => d.LicenceDocumentTypeCode == licAppFile.LicenceDocumentTypeCode)? - .ExpiryDate; - //create bcgov_documenturl and file - await _documentRepository.ManageAsync(new CreateDocumentCmd + IEnumerable items = await _cache.Get>(fileKeyCode.ToString()); + foreach (LicAppFileInfo licAppFile in items) { - TempFile = _mapper.Map(licAppFile), - ApplicationId = response.LicenceAppId, - DocumentType = docType1, - DocumentType2 = docType2, - SubmittedByApplicantId = response.ContactId, - ExpiryDate = expiredDate, - }, ct); + DocumentTypeEnum? docType1 = GetDocumentType1Enum(licAppFile.LicenceDocumentTypeCode); + DocumentTypeEnum? docType2 = GetDocumentType2Enum(licAppFile.LicenceDocumentTypeCode); + DateOnly? expiredDate = cmd.LicenceAnonymousRequest? + .DocumentInfos? + .FirstOrDefault(d => d.LicenceDocumentTypeCode == licAppFile.LicenceDocumentTypeCode)? + .ExpiryDate; + //create bcgov_documenturl and file + await _documentRepository.ManageAsync(new CreateDocumentCmd + { + TempFile = _mapper.Map(licAppFile), + ApplicationId = response.LicenceAppId, + DocumentType = docType1, + DocumentType2 = docType2, + SubmittedByApplicantId = response.ContactId, + ExpiryDate = expiredDate, + }, ct); + } } } + await CommitApplicationAsync(request, response.LicenceAppId, ct); + } + else + { + //update contact directly } - await CommitApplicationAsync(request, response.LicenceAppId, ct); + //check if criminal charges changes + //create task, assign to Licensing RA team + //New Offence Conviction + //(Licensing RA team - task) + //Hold a Position with Peace Officer Status + //(Licensing CS team - task high priority) + //Treated for Mental Health Condition + //(Licensing RA team - task) - return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId }; + return new WorkerLicenceAppUpsertResponse(); } #endregion diff --git a/src/Spd.Resource.Applicants/ServiceExtensions.cs b/src/Spd.Resource.Applicants/ServiceExtensions.cs index e74b4d429..3caad80b5 100644 --- a/src/Spd.Resource.Applicants/ServiceExtensions.cs +++ b/src/Spd.Resource.Applicants/ServiceExtensions.cs @@ -12,6 +12,7 @@ using Spd.Resource.Applicants.LicenceFee; using Spd.Resource.Applicants.Payment; using Spd.Resource.Applicants.PortalUser; +using Spd.Resource.Applicants.Task; using Spd.Utilities.Hosting; namespace Spd.Resource.Applicants @@ -33,6 +34,7 @@ public void ConfigureServices(ConfigurationServices configurationServices) configurationServices.Services.AddTransient(); configurationServices.Services.AddTransient(); configurationServices.Services.AddTransient(); + configurationServices.Services.AddTransient(); } } } diff --git a/src/Spd.Resource.Applicants/Task/Contract.cs b/src/Spd.Resource.Applicants/Task/Contract.cs new file mode 100644 index 000000000..371fa48eb --- /dev/null +++ b/src/Spd.Resource.Applicants/Task/Contract.cs @@ -0,0 +1,23 @@ +namespace Spd.Resource.Applicants.Task; +public partial interface ITaskRepository +{ + public Task QueryAsync(TaskQry query, CancellationToken cancellationToken); +} + + +public record TaskQry +{ + +}; + +public record TaskResp() +{ + +} + +public record TaskListResp +{ + public IEnumerable TaskResps { get; set; } = Array.Empty(); +} + + diff --git a/src/Spd.Resource.Applicants/Task/Mappings.cs b/src/Spd.Resource.Applicants/Task/Mappings.cs new file mode 100644 index 000000000..fe06f3e71 --- /dev/null +++ b/src/Spd.Resource.Applicants/Task/Mappings.cs @@ -0,0 +1,21 @@ +using AutoMapper; +using Microsoft.Dynamics.CRM; + +namespace Spd.Resource.Applicants.Task; + +internal class Mappings : Profile +{ + public Mappings() + { + + _ = CreateMap() + //.ForMember(d => d.WorkerLicenceTypeCode, opt => opt.MapFrom(s => DynamicsContextLookupHelpers.LookupServiceTypeKey(s._spd_servicetypeid_value))) + //.ForMember(d => d.BusinessTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetBusinessTypeEnum(s.spd_businesstype))) + //.ForMember(d => d.ApplicationTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetLicenceApplicationTypeEnum(s.spd_type))) + //.ForMember(d => d.LicenceTermCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetLicenceTermEnum(s.spd_term))) + //.ForMember(d => d.HasValidSwl90DayLicence, opt => opt.MapFrom(s => SharedMappingFuncs.GetBool(s.spd_hasvalidswl90daylicence))) + //.ForMember(d => d.Amount, opt => opt.MapFrom(s => s.spd_amount)) + ; + } +} + diff --git a/src/Spd.Resource.Applicants/Task/TaskRepository.cs b/src/Spd.Resource.Applicants/Task/TaskRepository.cs new file mode 100644 index 000000000..60444961f --- /dev/null +++ b/src/Spd.Resource.Applicants/Task/TaskRepository.cs @@ -0,0 +1,59 @@ +using AutoMapper; +using Microsoft.Dynamics.CRM; +using Microsoft.Extensions.Caching.Distributed; +using Spd.Utilities.Dynamics; + +namespace Spd.Resource.Applicants.Task; +internal class TaskRepository : ITaskRepository +{ + private readonly DynamicsContext _context; + private readonly IMapper _mapper; + + public TaskRepository(IDynamicsContextFactory ctx, IMapper mapper, IDistributedCache cache) + { + _context = ctx.Create(); + _mapper = mapper; + } + + public async Task QueryAsync(TaskQry qry, CancellationToken cancellationToken) + { + IEnumerable? feeResult = _context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).ToList(); + + //if (!qry.IncludeInactive) + // feeResult = feeResult.Where(d => d.statecode != DynamicsConstants.StateCode_Inactive); + + //if (qry.WorkerLicenceTypeEnum != null) + //{ + // DynamicsContextLookupHelpers.ServiceTypeGuidDictionary.TryGetValue(qry.WorkerLicenceTypeEnum.ToString(), out Guid stGuid); + // feeResult = feeResult.Where(f => f._spd_servicetypeid_value == stGuid); + //} + + //if (qry.LicenceTermEnum != null) + //{ + // int term = (int)Enum.Parse(qry.LicenceTermEnum.ToString()); + // feeResult = feeResult.Where(f => f.spd_term == term); + //} + + //if (qry.ApplicationTypeEnum != null) + //{ + // int type = (int)Enum.Parse(qry.ApplicationTypeEnum.ToString()); + // feeResult = feeResult.Where(f => f.spd_type == type); + //} + + //if (qry.BusinessTypeEnum != null) + //{ + // int bizType = (int)Enum.Parse(qry.BusinessTypeEnum.ToString()); + // feeResult = feeResult.Where(f => f.spd_businesstype == bizType); + //} + + //if (qry.HasValidSwl90DayLicence != null) + //{ + // int hasValidSwl90Day = (int)SharedMappingFuncs.GetYesNo(qry.HasValidSwl90DayLicence); + // feeResult = feeResult.Where(f => f.spd_hasvalidswl90daylicence == hasValidSwl90Day); + //} + var list = _mapper.Map>(feeResult); + var response = new TaskListResp(); + response.TaskResps = list; + return response; + } +} From ef647a60ba228e64c0b9bcdd51af71ce30a1b1ae Mon Sep 17 00:00:00 2001 From: peggy Date: Fri, 26 Jan 2024 10:41:10 -0800 Subject: [PATCH 3/6] temp unauth --- .../PersonalLicenceAppManager.cs | 17 +++++- .../Controllers/WorkerLicensingController.cs | 10 ++-- .../ApplicationRepository.Application.cs | 4 +- .../ApplicationRepository.Clearance.cs | 2 +- .../Application/Contract.Application.cs | 2 +- .../ApplicationInviteRepository.cs | 6 +- .../ApplicationInvite/Contract.cs | 10 ++-- .../ServiceExtensions.cs | 2 +- src/Spd.Resource.Applicants/Task/Contract.cs | 23 -------- src/Spd.Resource.Applicants/Task/Mappings.cs | 21 ------- .../Task/TaskRepository.cs | 59 ------------------- src/Spd.Resource.Applicants/Tasks/Contract.cs | 36 +++++++++++ src/Spd.Resource.Applicants/Tasks/Mappings.cs | 31 ++++++++++ .../Tasks/TaskRepository.cs | 34 +++++++++++ src/Spd.Utilities.Dynamics/OptionSets.cs | 7 +++ 15 files changed, 141 insertions(+), 123 deletions(-) delete mode 100644 src/Spd.Resource.Applicants/Task/Contract.cs delete mode 100644 src/Spd.Resource.Applicants/Task/Mappings.cs delete mode 100644 src/Spd.Resource.Applicants/Task/TaskRepository.cs create mode 100644 src/Spd.Resource.Applicants/Tasks/Contract.cs create mode 100644 src/Spd.Resource.Applicants/Tasks/Mappings.cs create mode 100644 src/Spd.Resource.Applicants/Tasks/TaskRepository.cs diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index 5c29eda1b..d2fa3c6f1 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -9,6 +9,7 @@ using Spd.Resource.Applicants.Licence; using Spd.Resource.Applicants.LicenceApplication; using Spd.Resource.Applicants.LicenceFee; +using Spd.Resource.Applicants.Tasks; using Spd.Resource.Organizations.Identity; using Spd.Utilities.Cache; using Spd.Utilities.Shared.Exceptions; @@ -25,6 +26,7 @@ internal partial class PersonalLicenceAppManager : IRequestHandler, IRequestHandler, IRequestHandler, + IRequestHandler, IRequestHandler>, IPersonalLicenceAppManager { @@ -36,6 +38,7 @@ internal partial class PersonalLicenceAppManager : private readonly IDocumentRepository _documentRepository; private readonly ILogger _logger; private readonly ILicenceFeeRepository _feeRepository; + private readonly ITaskRepository _taskRepository; private readonly IDistributedCache _cache; public PersonalLicenceAppManager( @@ -47,7 +50,8 @@ public PersonalLicenceAppManager( IDocumentRepository documentUrlRepository, ILogger logger, ILicenceFeeRepository feeRepository, - IDistributedCache cache) + IDistributedCache cache, + ITaskRepository taskRepository) { _licenceRepository = licenceRepository; _licenceAppRepository = licenceAppRepository; @@ -58,6 +62,7 @@ public PersonalLicenceAppManager( _logger = logger; _feeRepository = feeRepository; _cache = cache; + _taskRepository = taskRepository; } #region for portal @@ -89,7 +94,7 @@ public async Task Handle(WorkerLicenceUpsertComm return _mapper.Map(response); } - //authenticated submit + // authenticated submit public async Task Handle(WorkerLicenceSubmitCommand cmd, CancellationToken ct) { var response = await this.Handle((WorkerLicenceUpsertCommand)cmd, ct); @@ -317,6 +322,14 @@ await _documentRepository.ManageAsync( public async Task Handle(AnonymousWorkerLicenceAppUpdateCommand cmd, CancellationToken ct) { + await _taskRepository.ManageAsync(new CreateTaskCmd() + { + Description = "peggy test", + DueDate= new DateOnly(2024,2,20), + Subject = "subject", + TaskPriorityEnum = TaskPriorityEnum.High, + }, ct) ; + WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest; if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Update) throw new ArgumentException("should be a update request"); diff --git a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs index ca4598c18..d69694c8d 100644 --- a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs @@ -300,10 +300,10 @@ public async Task UploadLicenceAppFilesAnonymous([FromForm][Required] Lice public async Task SubmitSecurityWorkerLicenceApplicationJsonAnonymous(WorkerLicenceAppAnonymousSubmitRequestJson jsonRequest, Guid keyCode, CancellationToken ct) { //validate keyCode - if (await _cache.Get(keyCode.ToString()) == null) - { - throw new ApiException(HttpStatusCode.BadRequest, "invalid key code."); - } + //if (await _cache.Get(keyCode.ToString()) == null) + //{ + // throw new ApiException(HttpStatusCode.BadRequest, "invalid key code."); + //} _logger.LogInformation("validate payload"); var validateResult = await _anonymousLicenceAppSubmitRequestValidator.ValidateAsync(jsonRequest, ct); @@ -330,7 +330,7 @@ public async Task SubmitSecurityWorkerLicenceApp if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Update) { - AnonymousWorkerLicenceAppRenewCommand command = new(jsonRequest, keyCode); + AnonymousWorkerLicenceAppUpdateCommand command = new(jsonRequest, keyCode); return await _mediator.Send(command); } return null; diff --git a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs index d426a1d20..48747a341 100644 --- a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs +++ b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs @@ -73,7 +73,7 @@ public async Task QueryAsync(ApplicationListQry query, Canc return response; } - public async Task UpdateAsync(UpdateCmd cmd, CancellationToken cancellationToken) + public async System.Threading.Tasks.Task UpdateAsync(UpdateCmd cmd, CancellationToken cancellationToken) { spd_application? app = await _context.GetApplicationById(cmd.ApplicationId, cancellationToken); if (app == null) @@ -130,7 +130,7 @@ public async Task QueryApplicationAsync(ApplicationQry query, return _mapper.Map(application); } - public async Task ProcessAppWithSharableClearanceAsync(ApplicationCreateCmd createApplicationCmd, CancellationToken ct) + public async System.Threading.Tasks.Task ProcessAppWithSharableClearanceAsync(ApplicationCreateCmd createApplicationCmd, CancellationToken ct) { if (!createApplicationCmd.SharedClearanceId.HasValue) throw new ArgumentException("SharedClearanceId cannot be null"); diff --git a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs index 624456c10..c77d2c077 100644 --- a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs +++ b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs @@ -90,7 +90,7 @@ public async Task QueryAsync(ClearanceQry clearanceQry, Cance return resp; } - public async Task DeleteClearanceAccessAsync(ClearanceAccessDeleteCmd clearanceAccessDeleteCmd, CancellationToken cancellationToken) + public async System.Threading.Tasks.Task DeleteClearanceAccessAsync(ClearanceAccessDeleteCmd clearanceAccessDeleteCmd, CancellationToken cancellationToken) { var clearance = await GetClearanceAccessById(clearanceAccessDeleteCmd.ClearanceAccessId, clearanceAccessDeleteCmd.OrgId); diff --git a/src/Spd.Resource.Applicants/Application/Contract.Application.cs b/src/Spd.Resource.Applicants/Application/Contract.Application.cs index 2936f917c..03b1763c8 100644 --- a/src/Spd.Resource.Applicants/Application/Contract.Application.cs +++ b/src/Spd.Resource.Applicants/Application/Contract.Application.cs @@ -121,7 +121,7 @@ public record SpdTempFile public string ContentType { get; set; } = null!; public string FileName { get; set; } = null!; public long FileSize { get; set; } = 0; - public string? TempFilePath { get;set; } = null!;//it is the file location in the hard disk + public string? TempFilePath { get; set; } = null!;//it is the file location in the hard disk } public record ApplicationResult { diff --git a/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs b/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs index faa82c85b..7dafc3a6c 100644 --- a/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs +++ b/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs @@ -87,7 +87,7 @@ public async Task QueryAsync(ApplicationInviteQuery q return response; } - public async Task ManageAsync(ApplicationInviteCmd cmd, CancellationToken ct) + public async System.Threading.Tasks.Task ManageAsync(ApplicationInviteCmd cmd, CancellationToken ct) { if (cmd is ApplicationInvitesCreateCmd) await AddApplicationInvitesAsync((ApplicationInvitesCreateCmd)cmd, ct); @@ -95,7 +95,7 @@ public async Task ManageAsync(ApplicationInviteCmd cmd, CancellationToken ct) await UpdateApplicationInvitesAsync((ApplicationInviteUpdateCmd)cmd, ct); } - private async Task AddApplicationInvitesAsync(ApplicationInvitesCreateCmd createInviteCmd, CancellationToken ct) + private async System.Threading.Tasks.Task AddApplicationInvitesAsync(ApplicationInvitesCreateCmd createInviteCmd, CancellationToken ct) { spd_portaluser? user = await _dynaContext.GetUserById(createInviteCmd.CreatedByUserId, ct); if (createInviteCmd.OrgId != SpdConstants.BC_GOV_ORG_ID) @@ -148,7 +148,7 @@ private async Task AddApplicationInvitesAsync(ApplicationInvitesCreateCmd create await _dynaContext.SaveChangesAsync(ct); } - private async Task UpdateApplicationInvitesAsync(ApplicationInviteUpdateCmd applicationInviteUpdateCmd, CancellationToken cancellationToken) + private async System.Threading.Tasks.Task UpdateApplicationInvitesAsync(ApplicationInviteUpdateCmd applicationInviteUpdateCmd, CancellationToken cancellationToken) { spd_portalinvitation? invite = await GetPortalInvitationById(applicationInviteUpdateCmd.OrgId, applicationInviteUpdateCmd.ApplicationInviteId); diff --git a/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs b/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs index f9aed9816..4d3bd29f1 100644 --- a/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs +++ b/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs @@ -5,7 +5,7 @@ namespace Spd.Resource.Applicants.ApplicationInvite public interface IApplicationInviteRepository { public Task QueryAsync(ApplicationInviteQuery query, CancellationToken cancellationToken); - public Task ManageAsync(ApplicationInviteCmd query, CancellationToken cancellationToken); + public System.Threading.Tasks.Task ManageAsync(ApplicationInviteCmd query, CancellationToken cancellationToken); public Task VerifyApplicationInvitesAsync(ApplicationInviteVerifyCmd createInviteCmd, CancellationToken cancellationToken); } @@ -17,9 +17,9 @@ public record ApplicationInviteQuery } public interface ApplicationInviteCmd { }; - public record AppInviteFilterBy(Guid? OrgId, - string? EmailOrNameContains, - ServiceTypeEnum[]? ServiceTypes = null, + public record AppInviteFilterBy(Guid? OrgId, + string? EmailOrNameContains, + ServiceTypeEnum[]? ServiceTypes = null, Guid? AppInviteId = null, Guid? CreatedByUserId = null); public record AppInviteSortBy(bool? SubmittedDateDesc); @@ -32,7 +32,7 @@ public record ApplicationInviteResult : ApplicationInvite { public Guid Id { get; set; } public DateTimeOffset CreatedOn { get; set; } - public ApplicationInviteStatusEnum Status { get; set; } + public ApplicationInviteStatusEnum Status { get; set; } public string? ErrorMsg { get; set; } public bool? Viewed { get; set; } public Guid? CreatedByUserId { get; set; } diff --git a/src/Spd.Resource.Applicants/ServiceExtensions.cs b/src/Spd.Resource.Applicants/ServiceExtensions.cs index 3caad80b5..db13fb176 100644 --- a/src/Spd.Resource.Applicants/ServiceExtensions.cs +++ b/src/Spd.Resource.Applicants/ServiceExtensions.cs @@ -12,7 +12,7 @@ using Spd.Resource.Applicants.LicenceFee; using Spd.Resource.Applicants.Payment; using Spd.Resource.Applicants.PortalUser; -using Spd.Resource.Applicants.Task; +using Spd.Resource.Applicants.Tasks; using Spd.Utilities.Hosting; namespace Spd.Resource.Applicants diff --git a/src/Spd.Resource.Applicants/Task/Contract.cs b/src/Spd.Resource.Applicants/Task/Contract.cs deleted file mode 100644 index 371fa48eb..000000000 --- a/src/Spd.Resource.Applicants/Task/Contract.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Spd.Resource.Applicants.Task; -public partial interface ITaskRepository -{ - public Task QueryAsync(TaskQry query, CancellationToken cancellationToken); -} - - -public record TaskQry -{ - -}; - -public record TaskResp() -{ - -} - -public record TaskListResp -{ - public IEnumerable TaskResps { get; set; } = Array.Empty(); -} - - diff --git a/src/Spd.Resource.Applicants/Task/Mappings.cs b/src/Spd.Resource.Applicants/Task/Mappings.cs deleted file mode 100644 index fe06f3e71..000000000 --- a/src/Spd.Resource.Applicants/Task/Mappings.cs +++ /dev/null @@ -1,21 +0,0 @@ -using AutoMapper; -using Microsoft.Dynamics.CRM; - -namespace Spd.Resource.Applicants.Task; - -internal class Mappings : Profile -{ - public Mappings() - { - - _ = CreateMap() - //.ForMember(d => d.WorkerLicenceTypeCode, opt => opt.MapFrom(s => DynamicsContextLookupHelpers.LookupServiceTypeKey(s._spd_servicetypeid_value))) - //.ForMember(d => d.BusinessTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetBusinessTypeEnum(s.spd_businesstype))) - //.ForMember(d => d.ApplicationTypeCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetLicenceApplicationTypeEnum(s.spd_type))) - //.ForMember(d => d.LicenceTermCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetLicenceTermEnum(s.spd_term))) - //.ForMember(d => d.HasValidSwl90DayLicence, opt => opt.MapFrom(s => SharedMappingFuncs.GetBool(s.spd_hasvalidswl90daylicence))) - //.ForMember(d => d.Amount, opt => opt.MapFrom(s => s.spd_amount)) - ; - } -} - diff --git a/src/Spd.Resource.Applicants/Task/TaskRepository.cs b/src/Spd.Resource.Applicants/Task/TaskRepository.cs deleted file mode 100644 index 60444961f..000000000 --- a/src/Spd.Resource.Applicants/Task/TaskRepository.cs +++ /dev/null @@ -1,59 +0,0 @@ -using AutoMapper; -using Microsoft.Dynamics.CRM; -using Microsoft.Extensions.Caching.Distributed; -using Spd.Utilities.Dynamics; - -namespace Spd.Resource.Applicants.Task; -internal class TaskRepository : ITaskRepository -{ - private readonly DynamicsContext _context; - private readonly IMapper _mapper; - - public TaskRepository(IDynamicsContextFactory ctx, IMapper mapper, IDistributedCache cache) - { - _context = ctx.Create(); - _mapper = mapper; - } - - public async Task QueryAsync(TaskQry qry, CancellationToken cancellationToken) - { - IEnumerable? feeResult = _context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).ToList(); - - //if (!qry.IncludeInactive) - // feeResult = feeResult.Where(d => d.statecode != DynamicsConstants.StateCode_Inactive); - - //if (qry.WorkerLicenceTypeEnum != null) - //{ - // DynamicsContextLookupHelpers.ServiceTypeGuidDictionary.TryGetValue(qry.WorkerLicenceTypeEnum.ToString(), out Guid stGuid); - // feeResult = feeResult.Where(f => f._spd_servicetypeid_value == stGuid); - //} - - //if (qry.LicenceTermEnum != null) - //{ - // int term = (int)Enum.Parse(qry.LicenceTermEnum.ToString()); - // feeResult = feeResult.Where(f => f.spd_term == term); - //} - - //if (qry.ApplicationTypeEnum != null) - //{ - // int type = (int)Enum.Parse(qry.ApplicationTypeEnum.ToString()); - // feeResult = feeResult.Where(f => f.spd_type == type); - //} - - //if (qry.BusinessTypeEnum != null) - //{ - // int bizType = (int)Enum.Parse(qry.BusinessTypeEnum.ToString()); - // feeResult = feeResult.Where(f => f.spd_businesstype == bizType); - //} - - //if (qry.HasValidSwl90DayLicence != null) - //{ - // int hasValidSwl90Day = (int)SharedMappingFuncs.GetYesNo(qry.HasValidSwl90DayLicence); - // feeResult = feeResult.Where(f => f.spd_hasvalidswl90daylicence == hasValidSwl90Day); - //} - var list = _mapper.Map>(feeResult); - var response = new TaskListResp(); - response.TaskResps = list; - return response; - } -} diff --git a/src/Spd.Resource.Applicants/Tasks/Contract.cs b/src/Spd.Resource.Applicants/Tasks/Contract.cs new file mode 100644 index 000000000..a2966337c --- /dev/null +++ b/src/Spd.Resource.Applicants/Tasks/Contract.cs @@ -0,0 +1,36 @@ +namespace Spd.Resource.Applicants.Tasks; +public partial interface ITaskRepository +{ + public Task ManageAsync(TaskCmd query, CancellationToken cancellationToken); +} + +public abstract record TaskCmd; +public record CreateTaskCmd : TaskCmd +{ + public string Subject { get; set; } + public string Description { get; set; } + public TaskPriorityEnum TaskPriorityEnum { get; set; } + public DateOnly DueDate { get; set; } + public Guid? RegardingContactId { get; set; } + public Guid? RegardingCaseId { get; set; } + public Guid? TeamId { get; set; } +} +public record TaskResp() +{ + public Guid TaskId { get; set; } +} + +public record TaskListResp +{ + public IEnumerable TaskResps { get; set; } = Array.Empty(); +} + +public enum TaskPriorityEnum +{ + Low, + Normal, + High +} + + + diff --git a/src/Spd.Resource.Applicants/Tasks/Mappings.cs b/src/Spd.Resource.Applicants/Tasks/Mappings.cs new file mode 100644 index 000000000..d54dd1935 --- /dev/null +++ b/src/Spd.Resource.Applicants/Tasks/Mappings.cs @@ -0,0 +1,31 @@ +using AutoMapper; +using Microsoft.Dynamics.CRM; +using Spd.Utilities.Dynamics; + +namespace Spd.Resource.Applicants.Tasks; + +internal class Mappings : Profile +{ + public Mappings() + { + _ = CreateMap() + //.ForMember(d => d., opt => opt.MapFrom(s => s.Subject)) + .ForMember(d => d.subject, opt => opt.MapFrom(s => s.Subject)) + .ForMember(d => d.description, opt => opt.MapFrom(s => s.Description)) + .ForMember(d => d.prioritycode, opt => opt.MapFrom(s => s.TaskPriorityEnum)) + .ForMember(d => d.scheduledend, opt => opt.MapFrom(s => new DateTimeOffset(s.DueDate, new TimeOnly(0, 0), TimeSpan.FromSeconds(0)))); + } + + internal static int? GetPriority(TaskPriorityEnum? code) + { + if (code == null) return (int)TaskPriorityOptionSet.Normal; + return (int)Enum.Parse(code.ToString()); + } + + internal static TaskPriorityEnum? GetTaskPriorityEnum(int? optionset) + { + if (optionset == null) return null; + return Enum.Parse(Enum.GetName(typeof(TaskPriorityOptionSet), optionset)); + } +} + diff --git a/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs new file mode 100644 index 000000000..f0da83d9a --- /dev/null +++ b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs @@ -0,0 +1,34 @@ +using AutoMapper; +using Microsoft.Dynamics.CRM; +using Microsoft.Extensions.Caching.Distributed; +using Spd.Utilities.Dynamics; + +namespace Spd.Resource.Applicants.Tasks; +internal class TaskRepository : ITaskRepository +{ + private readonly DynamicsContext _context; + private readonly IMapper _mapper; + + public TaskRepository(IDynamicsContextFactory ctx, IMapper mapper, IDistributedCache cache) + { + _context = ctx.Create(); + _mapper = mapper; + } + + public async Task ManageAsync(TaskCmd cmd, CancellationToken ct) + { + return cmd switch + { + CreateTaskCmd c => await CreateTaskAsync(c, ct), + _ => throw new NotSupportedException($"{cmd.GetType().Name} is not supported") + }; + } + + private async Task CreateTaskAsync(CreateTaskCmd cmd, CancellationToken ct) + { + task t = _mapper.Map(cmd); + _context.AddTotasks(t); + await _context.SaveChangesAsync(ct); + return null; + } +} diff --git a/src/Spd.Utilities.Dynamics/OptionSets.cs b/src/Spd.Utilities.Dynamics/OptionSets.cs index b8aeda69c..4f7efbbb5 100644 --- a/src/Spd.Utilities.Dynamics/OptionSets.cs +++ b/src/Spd.Utilities.Dynamics/OptionSets.cs @@ -330,4 +330,11 @@ public enum AddressTypeOptionSet Mailing = 100000001, Branch = 100000002 } + + public enum TaskPriorityOptionSet + { + Low = 0, + Normal = 1, + High = 2 + } } From fb750015b5509d5b069590e17e0f89efcb5e62f7 Mon Sep 17 00:00:00 2001 From: peggy Date: Fri, 26 Jan 2024 16:33:41 -0800 Subject: [PATCH 4/6] create tasks --- .../PersonalLicenceAppManager.cs | 77 ++++++++++++++----- .../Controllers/WorkerLicensingController.cs | 1 + src/Spd.Resource.Applicants/Tasks/Contract.cs | 6 +- src/Spd.Resource.Applicants/Tasks/Mappings.cs | 4 +- .../Tasks/TaskRepository.cs | 31 +++++++- src/Spd.Utilities.Dynamics/Constants.cs | 1 + 6 files changed, 93 insertions(+), 27 deletions(-) diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index dcda22eab..1f053d30c 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -12,6 +12,7 @@ using Spd.Resource.Applicants.Tasks; using Spd.Resource.Organizations.Identity; using Spd.Utilities.Cache; +using Spd.Utilities.Dynamics; using Spd.Utilities.Shared.Exceptions; using Spd.Utilities.TempFileStorage; @@ -322,27 +323,22 @@ await _documentRepository.ManageAsync( public async Task Handle(AnonymousWorkerLicenceAppUpdateCommand cmd, CancellationToken ct) { - await _taskRepository.ManageAsync(new CreateTaskCmd() - { - Description = "peggy test", - DueDate= new DateOnly(2024,2,20), - Subject = "subject", - TaskPriorityEnum = TaskPriorityEnum.High, - }, ct) ; - WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest; if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Update) throw new ArgumentException("should be a update request"); - //validation: check if original licence meet replacement condition. + //validation: check if original licence meet update condition. LicenceListResp originalLicences = await _licenceRepository.QueryAsync(new LicenceQry() { LicenceId = request.OriginalLicenceId }, ct); if (originalLicences == null || !originalLicences.Items.Any()) throw new ArgumentException("cannot find the licence that needs to be updated."); LicenceResp originalLic = originalLicences.Items.First(); if (DateTime.UtcNow.AddDays(Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS) > originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) - throw new ArgumentException("can't request an update within 14 days of expiry date."); + throw new ArgumentException($"can't request an update within {Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS} days of expiry date."); - if ((request.Reprint != null && request.Reprint.Value) /*|| (CategoriesChanged or DogRestraint changed)*/) + LicenceApplicationResp originalApp = await _licenceAppRepository.GetLicenceApplicationAsync((Guid)cmd.LicenceAnonymousRequest.OriginalApplicationId, ct); + ChangeSpec changes = GetChanges(originalApp, request); + + if ((request.Reprint != null && request.Reprint.Value) || (changes.CategoriesChanged || changes.DogRestraintsChanged)) { CreateLicenceApplicationCmd createApp = _mapper.Map(request); var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct); @@ -374,6 +370,7 @@ await _documentRepository.ManageAsync(new CreateDocumentCmd } } } + //need to pay $20 await CommitApplicationAsync(request, response.LicenceAppId, ct); } else @@ -381,14 +378,41 @@ await _documentRepository.ManageAsync(new CreateDocumentCmd //update contact directly } - //check if criminal charges changes - //create task, assign to Licensing RA team - //New Offence Conviction - //(Licensing RA team - task) - //Hold a Position with Peace Officer Status - //(Licensing CS team - task high priority) - //Treated for Mental Health Condition - //(Licensing RA team - task) + //check if criminal charges changes or New Offence Conviction, create task, assign to Licensing RA Coordinator team + if (changes.CriminalHistoryChanged) + await _taskRepository.ManageAsync(new CreateTaskCmd() + { + Description = "Criminal History has Changed", + DueDateTime = new DateTimeOffset(2024, 2, 20, 0, 0, 0, new TimeSpan(0, 0, 0)), + Subject = "Criminal History Changed", + TaskPriorityEnum = TaskPriorityEnum.Normal, + RegardingContactId = originalApp.ContactId, + AssignedTeamId = Guid.Parse(DynamicsConstants.Licencing_Risk_Assessment_Coordinator_Team_Guid), + }, ct); + + // check if Hold a Position with Peace Officer Status changed, create task with high priority, assign to Licensing CS team + if (changes.PeaceOfficerStatusChanged) + await _taskRepository.ManageAsync(new CreateTaskCmd() + { + Description = "Peace Officer Status has Changed", + DueDateTime = new DateTimeOffset(2024, 2, 20, 0, 0, 0, new TimeSpan(0, 0, 0)), + Subject = "Peace Officer Status Changed", + TaskPriorityEnum = TaskPriorityEnum.High, + RegardingContactId = originalApp.ContactId, + AssignedTeamId = Guid.Parse(DynamicsConstants.Licensing_Client_Service_Team_Guid), + }, ct); + + ////Treated for Mental Health Condition, create task, assign to Licensing RA Coordinator team + if (changes.MentalHealthStatusChanged) + await _taskRepository.ManageAsync(new CreateTaskCmd() + { + Description = "Mental Health Status has Changed", + DueDateTime = new DateTimeOffset(2024, 2, 20, 0, 0, 0, new TimeSpan(0, 0, 0)), + Subject = "Mental Health Status Changed", + TaskPriorityEnum = TaskPriorityEnum.Normal, + RegardingContactId = originalApp.ContactId, + AssignedTeamId = Guid.Parse(DynamicsConstants.Licencing_Risk_Assessment_Coordinator_Team_Guid), + }, ct); return new WorkerLicenceAppUpsertResponse(); } @@ -460,4 +484,19 @@ private async Task HasDuplicates(Guid applicantId, WorkerLicenceTypeEnum w } return false; } + private ChangeSpec GetChanges(LicenceApplicationResp originalApp, WorkerLicenceAppAnonymousSubmitRequestJson newApp ) + { + return new ChangeSpec(); + } + + private record ChangeSpec + { + public bool NameChanged { get; set; } + public bool CategoriesChanged { get; set; } + public bool DogRestraintsChanged { get; set; } + public bool ContactInfoChanged { get; set; } + public bool PeaceOfficerStatusChanged { get; set; } + public bool MentalHealthStatusChanged { get; set; } + public bool CriminalHistoryChanged { get; set; } + } } diff --git a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs index d69694c8d..48cd9bf4f 100644 --- a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs @@ -299,6 +299,7 @@ public async Task UploadLicenceAppFilesAnonymous([FromForm][Required] Lice [HttpPost] public async Task SubmitSecurityWorkerLicenceApplicationJsonAnonymous(WorkerLicenceAppAnonymousSubmitRequestJson jsonRequest, Guid keyCode, CancellationToken ct) { + //temp remove, get it back when do pr. //validate keyCode //if (await _cache.Get(keyCode.ToString()) == null) //{ diff --git a/src/Spd.Resource.Applicants/Tasks/Contract.cs b/src/Spd.Resource.Applicants/Tasks/Contract.cs index a2966337c..c8fc8c3b6 100644 --- a/src/Spd.Resource.Applicants/Tasks/Contract.cs +++ b/src/Spd.Resource.Applicants/Tasks/Contract.cs @@ -1,7 +1,7 @@ namespace Spd.Resource.Applicants.Tasks; public partial interface ITaskRepository { - public Task ManageAsync(TaskCmd query, CancellationToken cancellationToken); + public Task ManageAsync(TaskCmd cmd, CancellationToken ct); } public abstract record TaskCmd; @@ -10,10 +10,10 @@ public record CreateTaskCmd : TaskCmd public string Subject { get; set; } public string Description { get; set; } public TaskPriorityEnum TaskPriorityEnum { get; set; } - public DateOnly DueDate { get; set; } + public DateTimeOffset DueDateTime { get; set; } public Guid? RegardingContactId { get; set; } public Guid? RegardingCaseId { get; set; } - public Guid? TeamId { get; set; } + public Guid? AssignedTeamId { get; set; } } public record TaskResp() { diff --git a/src/Spd.Resource.Applicants/Tasks/Mappings.cs b/src/Spd.Resource.Applicants/Tasks/Mappings.cs index d54dd1935..c268db8cd 100644 --- a/src/Spd.Resource.Applicants/Tasks/Mappings.cs +++ b/src/Spd.Resource.Applicants/Tasks/Mappings.cs @@ -9,11 +9,11 @@ internal class Mappings : Profile public Mappings() { _ = CreateMap() - //.ForMember(d => d., opt => opt.MapFrom(s => s.Subject)) + .ForMember(d => d.activityid, opt => opt.MapFrom(s => Guid.NewGuid())) .ForMember(d => d.subject, opt => opt.MapFrom(s => s.Subject)) .ForMember(d => d.description, opt => opt.MapFrom(s => s.Description)) .ForMember(d => d.prioritycode, opt => opt.MapFrom(s => s.TaskPriorityEnum)) - .ForMember(d => d.scheduledend, opt => opt.MapFrom(s => new DateTimeOffset(s.DueDate, new TimeOnly(0, 0), TimeSpan.FromSeconds(0)))); + .ForMember(d => d.scheduledend, opt => opt.MapFrom(s => s.DueDateTime)); } internal static int? GetPriority(TaskPriorityEnum? code) diff --git a/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs index f0da83d9a..9bbc00c41 100644 --- a/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs +++ b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs @@ -1,6 +1,5 @@ using AutoMapper; using Microsoft.Dynamics.CRM; -using Microsoft.Extensions.Caching.Distributed; using Spd.Utilities.Dynamics; namespace Spd.Resource.Applicants.Tasks; @@ -9,7 +8,7 @@ internal class TaskRepository : ITaskRepository private readonly DynamicsContext _context; private readonly IMapper _mapper; - public TaskRepository(IDynamicsContextFactory ctx, IMapper mapper, IDistributedCache cache) + public TaskRepository(IDynamicsContextFactory ctx, IMapper mapper) { _context = ctx.Create(); _mapper = mapper; @@ -28,7 +27,33 @@ private async Task CreateTaskAsync(CreateTaskCmd cmd, CancellationToke { task t = _mapper.Map(cmd); _context.AddTotasks(t); + + if (cmd.RegardingContactId != null) + { + contact? contact = _context.contacts.Where(c => c.contactid == cmd.RegardingContactId).FirstOrDefault(); + if (contact == null) + { + throw new ArgumentException($"cannot find contact for contactid = {cmd.RegardingContactId}."); + } + _context.SetLink(t, nameof(t.regardingobjectid_contact), contact); + } + + if (cmd.RegardingCaseId != null) + { + incident? incident = _context.incidents.Where(c => c.incidentid == cmd.RegardingCaseId).FirstOrDefault(); + if (incident == null) + { + throw new ArgumentException($"cannot find contact for incidentid = {cmd.RegardingCaseId}."); + } + _context.SetLink(t, nameof(t.regardingobjectid_incident), incident); + } + + if(cmd.AssignedTeamId != null) + { + team? serviceTeam = await _context.teams.Where(t => t.teamid == cmd.AssignedTeamId).FirstOrDefaultAsync(ct); + _context.SetLink(t, nameof(t.ownerid), serviceTeam); + } await _context.SaveChangesAsync(ct); - return null; + return new TaskResp { TaskId = (Guid)t.activityid }; } } diff --git a/src/Spd.Utilities.Dynamics/Constants.cs b/src/Spd.Utilities.Dynamics/Constants.cs index 481732e46..f2c7e77ab 100644 --- a/src/Spd.Utilities.Dynamics/Constants.cs +++ b/src/Spd.Utilities.Dynamics/Constants.cs @@ -8,5 +8,6 @@ public class DynamicsConstants public static readonly int StatusCode_Inactive = 2; public static readonly string Client_Service_Team_Guid = "65e0b015-ee9d-ed11-b83d-00505683fbf4"; public static readonly string Licensing_Client_Service_Team_Guid = "9872da9f-397f-ee11-b846-00505683fbf4"; + public static readonly string Licencing_Risk_Assessment_Coordinator_Team_Guid = "b322c8f6-a8eb-ed11-b843-00505683fbf4"; } } From 8ec72ff9f3f117892347e90734d35c28e33947c6 Mon Sep 17 00:00:00 2001 From: peggy Date: Fri, 26 Jan 2024 16:58:24 -0800 Subject: [PATCH 5/6] cleanup --- .../PersonalLicenceAppManager.cs | 14 ++++++----- .../Controllers/WorkerLicensingController.cs | 24 +++++++++---------- .../ApplicationRepository.Application.cs | 24 +++++++++---------- .../ApplicationRepository.Clearance.cs | 2 +- .../ApplicationInviteRepository.cs | 6 ++--- .../ApplicationInvite/Contract.cs | 2 +- src/Spd.Resource.Applicants/Tasks/Mappings.cs | 2 +- .../Tasks/TaskRepository.cs | 4 ++-- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index 1f053d30c..0fb6c8454 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -1,7 +1,5 @@ using AutoMapper; using MediatR; -using Microsoft.AspNetCore.Http.HttpResults; -using Microsoft.Dynamics.CRM; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; using Spd.Resource.Applicants.Application; @@ -370,12 +368,12 @@ await _documentRepository.ManageAsync(new CreateDocumentCmd } } } - //need to pay $20 + //todo : need to pay $20 await CommitApplicationAsync(request, response.LicenceAppId, ct); } else { - //update contact directly + //todo: update contact directly } //check if criminal charges changes or New Offence Conviction, create task, assign to Licensing RA Coordinator team @@ -484,9 +482,13 @@ private async Task HasDuplicates(Guid applicantId, WorkerLicenceTypeEnum w } return false; } - private ChangeSpec GetChanges(LicenceApplicationResp originalApp, WorkerLicenceAppAnonymousSubmitRequestJson newApp ) + private ChangeSpec GetChanges(LicenceApplicationResp originalApp, WorkerLicenceAppAnonymousSubmitRequestJson newApp) { - return new ChangeSpec(); + ChangeSpec changes = new ChangeSpec(); + //todo + //if(newApp.CategoryCodes != originalApp.CategoryData) + changes.CategoriesChanged = true; + return changes; } private record ChangeSpec diff --git a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs index 48cd9bf4f..1b30bb65a 100644 --- a/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/WorkerLicensingController.cs @@ -171,7 +171,6 @@ public async Task> GetLicenceApplicati /// Submit Security Worker Licence Application Anonymously /// deprecated as the request body is too big. the proxy won't let it through. /// - /// /// [Route("api/worker-licence-applications/submit/anonymous")] [HttpPost] @@ -283,7 +282,7 @@ public async Task UploadLicenceAppFilesAnonymous([FromForm][Required] Lice } CreateDocumentInCacheCommand command = new CreateDocumentInCacheCommand(fileUploadRequest); - var newFileInfos = await _mediator.Send(command); + var newFileInfos = await _mediator.Send(command, ct); Guid fileKeyCode = Guid.NewGuid(); await _cache.Set>(fileKeyCode.ToString(), newFileInfos, TimeSpan.FromMinutes(30)); return fileKeyCode; @@ -293,18 +292,17 @@ public async Task UploadLicenceAppFilesAnonymous([FromForm][Required] Lice /// Submit Security Worker Licence Application Json part Anonymously /// After fe done with the uploading files, then fe do post with json payload, inside payload, it needs to contain an array of keycode for the files. /// - /// + /// WorkerLicenceAppAnonymousSubmitRequestJson data /// [Route("api/worker-licence-applications/anonymous/{keyCode}/submit")] [HttpPost] public async Task SubmitSecurityWorkerLicenceApplicationJsonAnonymous(WorkerLicenceAppAnonymousSubmitRequestJson jsonRequest, Guid keyCode, CancellationToken ct) { - //temp remove, get it back when do pr. //validate keyCode - //if (await _cache.Get(keyCode.ToString()) == null) - //{ - // throw new ApiException(HttpStatusCode.BadRequest, "invalid key code."); - //} + if (await _cache.Get(keyCode.ToString()) == null) + { + throw new ApiException(HttpStatusCode.BadRequest, "invalid key code."); + } _logger.LogInformation("validate payload"); var validateResult = await _anonymousLicenceAppSubmitRequestValidator.ValidateAsync(jsonRequest, ct); @@ -314,25 +312,25 @@ public async Task SubmitSecurityWorkerLicenceApp if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.New) { AnonymousWorkerLicenceAppNewCommand command = new(jsonRequest, keyCode); - return await _mediator.Send(command); + return await _mediator.Send(command, ct); } if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Replacement) { AnonymousWorkerLicenceAppReplaceCommand command = new(jsonRequest, keyCode); - return await _mediator.Send(command); + return await _mediator.Send(command, ct); } if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Renewal) { AnonymousWorkerLicenceAppRenewCommand command = new(jsonRequest, keyCode); - return await _mediator.Send(command); + return await _mediator.Send(command, ct); } if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Update) { AnonymousWorkerLicenceAppUpdateCommand command = new(jsonRequest, keyCode); - return await _mediator.Send(command); + return await _mediator.Send(command, ct); } return null; } @@ -341,6 +339,6 @@ public async Task SubmitSecurityWorkerLicenceApp public class GoogleRecaptcha { - public string RecaptchaCode { get; set; } + public string RecaptchaCode { get; set; } = null!; } } \ No newline at end of file diff --git a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs index 48747a341..7c088b4b8 100644 --- a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs +++ b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Application.cs @@ -73,9 +73,9 @@ public async Task QueryAsync(ApplicationListQry query, Canc return response; } - public async System.Threading.Tasks.Task UpdateAsync(UpdateCmd cmd, CancellationToken cancellationToken) + public async Task UpdateAsync(UpdateCmd cmd, CancellationToken ct) { - spd_application? app = await _context.GetApplicationById(cmd.ApplicationId, cancellationToken); + spd_application? app = await _context.GetApplicationById(cmd.ApplicationId, ct); if (app == null) throw new ApiException(HttpStatusCode.BadRequest, "Invalid ApplicationId"); @@ -88,18 +88,18 @@ public async System.Threading.Tasks.Task UpdateAsync(UpdateCmd cmd, Cancellation app.statecode = DynamicsConstants.StateCode_Active; } _context.UpdateObject(app); - await _context.SaveChangesAsync(cancellationToken); + await _context.SaveChangesAsync(ct); } - public async Task CheckApplicationDuplicateAsync(SearchApplicationQry searchApplicationQry, CancellationToken cancellationToken) + public async Task CheckApplicationDuplicateAsync(SearchApplicationQry searchApplicationQry, CancellationToken ct) { - var application = _context.spd_applications.Where(o => + var application = await _context.spd_applications.Where(o => o.spd_OrganizationId.accountid == searchApplicationQry.OrgId && o.spd_firstname == searchApplicationQry.GivenName && o.spd_lastname == searchApplicationQry.Surname && o.spd_dateofbirth == new Microsoft.OData.Edm.Date(searchApplicationQry.DateOfBirth.Value.Year, searchApplicationQry.DateOfBirth.Value.Month, searchApplicationQry.DateOfBirth.Value.Day) && o.statecode != DynamicsConstants.StateCode_Inactive - ).FirstOrDefault(); + ).FirstOrDefaultAsync(ct); return application != null; } @@ -120,17 +120,17 @@ public async Task QueryApplicantApplicationListAsy return response; } - public async Task QueryApplicationAsync(ApplicationQry query, CancellationToken cancellationToken) + public async Task QueryApplicationAsync(ApplicationQry query, CancellationToken ct) { - var application = _context.spd_applications + var application = await _context.spd_applications .Expand(i => i.spd_OrganizationId) .Expand(i => i.spd_ApplicantId_contact) .Where(r => r.spd_applicationid == query.ApplicationId) - .FirstOrDefault(); + .FirstOrDefaultAsync(ct); return _mapper.Map(application); } - public async System.Threading.Tasks.Task ProcessAppWithSharableClearanceAsync(ApplicationCreateCmd createApplicationCmd, CancellationToken ct) + public async Task ProcessAppWithSharableClearanceAsync(ApplicationCreateCmd createApplicationCmd, CancellationToken ct) { if (!createApplicationCmd.SharedClearanceId.HasValue) throw new ArgumentException("SharedClearanceId cannot be null"); @@ -187,7 +187,7 @@ public async System.Threading.Tasks.Task ProcessAppWithSharableClearanceAsync(Ap } } - private string GetAppFilterString(AppFilterBy appFilterBy) + private static string GetAppFilterString(AppFilterBy appFilterBy) { //orgfilter string? orgFilter = null; @@ -314,7 +314,7 @@ private string GetAppFilterString(AppFilterBy appFilterBy) return result; } - private string GetAppSortString(AppSortBy? appSortBy) + private static string GetAppSortString(AppSortBy? appSortBy) { if (appSortBy == null || (appSortBy.SubmittedDateDesc != null && (bool)appSortBy.SubmittedDateDesc)) diff --git a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs index c77d2c077..624456c10 100644 --- a/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs +++ b/src/Spd.Resource.Applicants/Application/ApplicationRepository.Clearance.cs @@ -90,7 +90,7 @@ public async Task QueryAsync(ClearanceQry clearanceQry, Cance return resp; } - public async System.Threading.Tasks.Task DeleteClearanceAccessAsync(ClearanceAccessDeleteCmd clearanceAccessDeleteCmd, CancellationToken cancellationToken) + public async Task DeleteClearanceAccessAsync(ClearanceAccessDeleteCmd clearanceAccessDeleteCmd, CancellationToken cancellationToken) { var clearance = await GetClearanceAccessById(clearanceAccessDeleteCmd.ClearanceAccessId, clearanceAccessDeleteCmd.OrgId); diff --git a/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs b/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs index 7dafc3a6c..faa82c85b 100644 --- a/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs +++ b/src/Spd.Resource.Applicants/ApplicationInvite/ApplicationInviteRepository.cs @@ -87,7 +87,7 @@ public async Task QueryAsync(ApplicationInviteQuery q return response; } - public async System.Threading.Tasks.Task ManageAsync(ApplicationInviteCmd cmd, CancellationToken ct) + public async Task ManageAsync(ApplicationInviteCmd cmd, CancellationToken ct) { if (cmd is ApplicationInvitesCreateCmd) await AddApplicationInvitesAsync((ApplicationInvitesCreateCmd)cmd, ct); @@ -95,7 +95,7 @@ public async System.Threading.Tasks.Task ManageAsync(ApplicationInviteCmd cmd, C await UpdateApplicationInvitesAsync((ApplicationInviteUpdateCmd)cmd, ct); } - private async System.Threading.Tasks.Task AddApplicationInvitesAsync(ApplicationInvitesCreateCmd createInviteCmd, CancellationToken ct) + private async Task AddApplicationInvitesAsync(ApplicationInvitesCreateCmd createInviteCmd, CancellationToken ct) { spd_portaluser? user = await _dynaContext.GetUserById(createInviteCmd.CreatedByUserId, ct); if (createInviteCmd.OrgId != SpdConstants.BC_GOV_ORG_ID) @@ -148,7 +148,7 @@ private async System.Threading.Tasks.Task AddApplicationInvitesAsync(Application await _dynaContext.SaveChangesAsync(ct); } - private async System.Threading.Tasks.Task UpdateApplicationInvitesAsync(ApplicationInviteUpdateCmd applicationInviteUpdateCmd, CancellationToken cancellationToken) + private async Task UpdateApplicationInvitesAsync(ApplicationInviteUpdateCmd applicationInviteUpdateCmd, CancellationToken cancellationToken) { spd_portalinvitation? invite = await GetPortalInvitationById(applicationInviteUpdateCmd.OrgId, applicationInviteUpdateCmd.ApplicationInviteId); diff --git a/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs b/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs index 4d3bd29f1..677beafde 100644 --- a/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs +++ b/src/Spd.Resource.Applicants/ApplicationInvite/Contract.cs @@ -5,7 +5,7 @@ namespace Spd.Resource.Applicants.ApplicationInvite public interface IApplicationInviteRepository { public Task QueryAsync(ApplicationInviteQuery query, CancellationToken cancellationToken); - public System.Threading.Tasks.Task ManageAsync(ApplicationInviteCmd query, CancellationToken cancellationToken); + public Task ManageAsync(ApplicationInviteCmd query, CancellationToken cancellationToken); public Task VerifyApplicationInvitesAsync(ApplicationInviteVerifyCmd createInviteCmd, CancellationToken cancellationToken); } diff --git a/src/Spd.Resource.Applicants/Tasks/Mappings.cs b/src/Spd.Resource.Applicants/Tasks/Mappings.cs index c268db8cd..a99f3a909 100644 --- a/src/Spd.Resource.Applicants/Tasks/Mappings.cs +++ b/src/Spd.Resource.Applicants/Tasks/Mappings.cs @@ -12,7 +12,7 @@ public Mappings() .ForMember(d => d.activityid, opt => opt.MapFrom(s => Guid.NewGuid())) .ForMember(d => d.subject, opt => opt.MapFrom(s => s.Subject)) .ForMember(d => d.description, opt => opt.MapFrom(s => s.Description)) - .ForMember(d => d.prioritycode, opt => opt.MapFrom(s => s.TaskPriorityEnum)) + .ForMember(d => d.prioritycode, opt => opt.MapFrom(s => GetPriority(s.TaskPriorityEnum))) .ForMember(d => d.scheduledend, opt => opt.MapFrom(s => s.DueDateTime)); } diff --git a/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs index 9bbc00c41..89241cdc8 100644 --- a/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs +++ b/src/Spd.Resource.Applicants/Tasks/TaskRepository.cs @@ -48,12 +48,12 @@ private async Task CreateTaskAsync(CreateTaskCmd cmd, CancellationToke _context.SetLink(t, nameof(t.regardingobjectid_incident), incident); } - if(cmd.AssignedTeamId != null) + if (cmd.AssignedTeamId != null) { team? serviceTeam = await _context.teams.Where(t => t.teamid == cmd.AssignedTeamId).FirstOrDefaultAsync(ct); _context.SetLink(t, nameof(t.ownerid), serviceTeam); } await _context.SaveChangesAsync(ct); - return new TaskResp { TaskId = (Guid)t.activityid }; + return new TaskResp { TaskId = t.activityid ?? Guid.Empty }; } } From 6620d8c42be425b288dd5c773964147afa2dba61 Mon Sep 17 00:00:00 2001 From: peggy Date: Fri, 26 Jan 2024 17:32:21 -0800 Subject: [PATCH 6/6] update renew validation --- src/Spd.Manager.Licence/Constants.cs | 9 ++++---- .../PersonalLicenceAppManager.cs | 21 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Spd.Manager.Licence/Constants.cs b/src/Spd.Manager.Licence/Constants.cs index 0c1944f0e..d493bb2bd 100644 --- a/src/Spd.Manager.Licence/Constants.cs +++ b/src/Spd.Manager.Licence/Constants.cs @@ -1,7 +1,8 @@ namespace Spd.Manager.Licence; -internal class Constants +internal static class Constants { - public static readonly int LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS = 14; - public static readonly int LICENCE_RENEW_VALID_BEFORE_EXPIRATION_IN_DAYS = 90; - public static readonly int LICENCE_UPDATE_VALID_BEFORE_EXPIRATION_IN_DAYS = 14;//Licence holder can't request an update within 14 days of expiry date + internal const int LicenceReplaceValidBeforeExpirationInDays = 14; + internal const int LicenceWith123YearsRenewValidBeforeExpirationInDays = 90; + internal const int LicenceWith90DaysRenewValidBeforeExpirationInDays = 60; + internal const int LicenceUpdateValidBeforeExpirationInDays = 14;//Licence holder can't request an update within 14 days of expiry date } diff --git a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs index 0fb6c8454..aecca211e 100644 --- a/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs +++ b/src/Spd.Manager.Licence/PersonalLicenceAppManager.cs @@ -225,7 +225,7 @@ public async Task Handle(AnonymousWorkerLicenceA LicenceListResp licences = await _licenceRepository.QueryAsync(new LicenceQry() { LicenceId = request.OriginalLicenceId }, ct); if (licences == null || !licences.Items.Any()) throw new ArgumentException("cannot find the licence that needs to be replaced."); - if (DateTime.UtcNow.AddDays(Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS) > licences.Items.First().ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + if (DateTime.UtcNow.AddDays(Constants.LicenceReplaceValidBeforeExpirationInDays) > licences.Items.First().ExpiryDate.ToDateTime(new TimeOnly(0, 0))) throw new ArgumentException("the licence cannot be replaced because it will expired soon or already expired"); CreateLicenceApplicationCmd createApp = _mapper.Map(request); @@ -264,9 +264,18 @@ public async Task Handle(AnonymousWorkerLicenceA if (originalLicences == null || !originalLicences.Items.Any()) throw new ArgumentException("cannot find the licence that needs to be renewed."); LicenceResp originalLic = originalLicences.Items.First(); - if (DateTime.UtcNow > originalLic.ExpiryDate.AddDays(Constants.LICENCE_RENEW_VALID_BEFORE_EXPIRATION_IN_DAYS).ToDateTime(new TimeOnly(0, 0)) - && DateTime.UtcNow < originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) - throw new ArgumentException("the licence can only be renewed within 90 days of the expiry date."); + if (originalLic.LicenceTermCode == LicenceTermEnum.NinetyDays) + { + if (DateTime.UtcNow > originalLic.ExpiryDate.AddDays(-Constants.LicenceWith90DaysRenewValidBeforeExpirationInDays).ToDateTime(new TimeOnly(0, 0)) + && DateTime.UtcNow < originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + throw new ArgumentException($"the licence can only be renewed within {Constants.LicenceWith90DaysRenewValidBeforeExpirationInDays} days of the expiry date."); + } + else + { + if (DateTime.UtcNow > originalLic.ExpiryDate.AddDays(-Constants.LicenceWith123YearsRenewValidBeforeExpirationInDays).ToDateTime(new TimeOnly(0, 0)) + && DateTime.UtcNow < originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + throw new ArgumentException($"the licence can only be renewed within {Constants.LicenceWith123YearsRenewValidBeforeExpirationInDays} days of the expiry date."); + } CreateLicenceApplicationCmd createApp = _mapper.Map(request); var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct); @@ -330,8 +339,8 @@ public async Task Handle(AnonymousWorkerLicenceA if (originalLicences == null || !originalLicences.Items.Any()) throw new ArgumentException("cannot find the licence that needs to be updated."); LicenceResp originalLic = originalLicences.Items.First(); - if (DateTime.UtcNow.AddDays(Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS) > originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) - throw new ArgumentException($"can't request an update within {Constants.LICENCE_REPLACE_VALID_BEFORE_EXPIRATION_IN_DAYS} days of expiry date."); + if (DateTime.UtcNow.AddDays(Constants.LicenceUpdateValidBeforeExpirationInDays) > originalLic.ExpiryDate.ToDateTime(new TimeOnly(0, 0))) + throw new ArgumentException($"can't request an update within {Constants.LicenceUpdateValidBeforeExpirationInDays} days of expiry date."); LicenceApplicationResp originalApp = await _licenceAppRepository.GetLicenceApplicationAsync((Guid)cmd.LicenceAnonymousRequest.OriginalApplicationId, ct); ChangeSpec changes = GetChanges(originalApp, request);