diff --git a/src/Spd.Manager.Licence/BizLicAppContract.cs b/src/Spd.Manager.Licence/BizLicAppContract.cs index 8bf5f7f6e..3c2a3a768 100644 --- a/src/Spd.Manager.Licence/BizLicAppContract.cs +++ b/src/Spd.Manager.Licence/BizLicAppContract.cs @@ -14,6 +14,7 @@ public interface IBizLicAppManager public Task Handle(BizLicAppUpdateCommand command, CancellationToken ct); public Task> Handle(GetBizLicAppListQuery cmd, CancellationToken ct); public Task Handle(BrandImageQuery qry, CancellationToken ct); + public Task Handle(CancelDraftApplicationCommand cmd, CancellationToken ct); } public record BizLicAppUpsertCommand(BizLicAppUpsertRequest BizLicAppUpsertRequest) : IRequest; @@ -22,6 +23,8 @@ public record BizLicAppSubmitCommand(BizLicAppUpsertRequest BizLicAppUpsertReque public record GetBizLicAppQuery(Guid LicenceApplicationId) : IRequest; public record GetLatestBizLicenceAppQuery(Guid BizId) : IRequest; public record GetBizLicAppListQuery(Guid BizId) : IRequest>; +public record CancelDraftApplicationCommand(Guid ApplicationId) : IRequest; + public record BizLicAppReplaceCommand( BizLicAppSubmitRequest LicenceRequest, IEnumerable LicAppFileInfos) diff --git a/src/Spd.Manager.Licence/BizLicAppManager.cs b/src/Spd.Manager.Licence/BizLicAppManager.cs index 781f67cbd..e3f6907bf 100644 --- a/src/Spd.Manager.Licence/BizLicAppManager.cs +++ b/src/Spd.Manager.Licence/BizLicAppManager.cs @@ -30,6 +30,7 @@ internal class BizLicAppManager : IRequestHandler, IRequestHandler>, IRequestHandler, + IRequestHandler, IBizLicAppManager { private readonly IBizLicApplicationRepository _bizLicApplicationRepository; @@ -356,6 +357,18 @@ public async Task Handle(BrandImageQuery qry, CancellationToken ct return new FileResponse(); //error in S3, probably cannot find the file } } + public async Task Handle(CancelDraftApplicationCommand cmd, CancellationToken ct) + { + try + { + await _bizLicApplicationRepository.CancelDraftApplicationAsync(cmd.ApplicationId, ct); + } + catch (ArgumentException e) + { + throw new ApiException(HttpStatusCode.Forbidden, e.Message); + }; + return default; + } private async Task ValidateFilesForRenewUpdateAppAsync(BizLicAppSubmitRequest request, IList newFileInfos, diff --git a/src/Spd.Presentation.Licensing/Controllers/LicenceAppController.cs b/src/Spd.Presentation.Licensing/Controllers/LicenceAppController.cs index e85691e1f..1cb70b975 100644 --- a/src/Spd.Presentation.Licensing/Controllers/LicenceAppController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/LicenceAppController.cs @@ -49,5 +49,20 @@ public async Task> GetBizLicenceApplications { return await _mediator.Send(new GetBizLicAppListQuery(bizId), ct); } + + /// + /// Cancel Draft Application + /// + /// + /// + /// + [Route("api/applications/{appId}")] + [HttpDelete] + [Authorize(Policy = "BcscBCeID")] + public async Task CancelDraftApplication([FromRoute] Guid appId, CancellationToken ct) + { + await _mediator.Send(new CancelDraftApplicationCommand(appId), ct); + return Ok(); + } } } \ No newline at end of file diff --git a/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs b/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs index 371f336cd..8b229876c 100644 --- a/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs +++ b/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs @@ -1,4 +1,6 @@ using AutoMapper; +using MediatR; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.Dynamics.CRM; using Microsoft.OData.Client; using Spd.Resource.Repository.PersonLicApplication; @@ -356,4 +358,20 @@ private spd_licence GetLicence(Guid licenceId) return licence; } + + public async Task CancelDraftApplicationAsync(Guid applicationId, CancellationToken ct) + { + spd_application? app = _context.spd_applications.Where(a => a.spd_applicationid == applicationId).FirstOrDefault(); + if (app == null) + throw new ArgumentException("Application not found"); + if (app.spd_licenceapplicationtype == (int)LicenceApplicationTypeOptionSet.New) + throw new ArgumentException("Canceling application with this type is not allowed."); + if (app.statuscode != (int)ApplicationStatusOptionSet.Draft && app.statuscode != (int)ApplicationStatusOptionSet.Incomplete) + throw new ArgumentException("Canceling application with this status is not allowed."); + + app.statecode = DynamicsConstants.StateCode_Inactive; + app.statuscode = (int) ApplicationStatusOptionSet.Cancelled; + _context.UpdateObject(app); + await _context.SaveChangesAsync(ct); + } } diff --git a/src/Spd.Resource.Repository/BizLicApplication/Contract.cs b/src/Spd.Resource.Repository/BizLicApplication/Contract.cs index 380a832d9..15104cb46 100644 --- a/src/Spd.Resource.Repository/BizLicApplication/Contract.cs +++ b/src/Spd.Resource.Repository/BizLicApplication/Contract.cs @@ -1,4 +1,5 @@ -using Spd.Resource.Repository.Application; +using MediatR; +using Spd.Resource.Repository.Application; using Spd.Resource.Repository.Biz; using Spd.Resource.Repository.PersonLicApplication; @@ -8,6 +9,7 @@ public partial interface IBizLicApplicationRepository public Task CreateBizLicApplicationAsync(CreateBizLicApplicationCmd cmd, CancellationToken ct); public Task SaveBizLicApplicationAsync(SaveBizLicApplicationCmd cmd, CancellationToken ct); public Task GetBizLicApplicationAsync(Guid licenceApplicationId, CancellationToken ct); + public Task CancelDraftApplicationAsync(Guid applicationId, CancellationToken ct); } public record BizLicApplicationCmdResp(Guid LicenceAppId, Guid AccountId);