18
18
using Spd . Resource . Repository . LicApp ;
19
19
using Spd . Resource . Repository . PersonLicApplication ;
20
20
using Spd . Resource . Repository . Application ;
21
+ using Spd . Resource . Repository . ApplicationInvite ;
22
+ using Spd . Resource . Repository ;
21
23
22
24
namespace Spd . Manager . Licence ;
23
25
internal class ControllingMemberCrcAppManager :
24
26
LicenceAppManagerBase ,
25
27
IRequestHandler < ControllingMemberCrcAppNewCommand , ControllingMemberCrcAppCommandResponse > ,
28
+ IRequestHandler < ControllingMemberCrcUpsertCommand , ControllingMemberCrcAppCommandResponse > ,
29
+ IRequestHandler < ControllingMemberCrcSubmitCommand , ControllingMemberCrcAppCommandResponse > ,
30
+ IRequestHandler < GetControllingMemberCrcApplicationQuery , ControllingMemberCrcAppResponse > ,
26
31
IControllingMemberCrcAppManager
27
32
{
28
33
private readonly IControllingMemberCrcRepository _controllingMemberCrcRepository ;
34
+ private readonly IApplicationInviteRepository _applicationInviteRepository ;
29
35
30
36
public ControllingMemberCrcAppManager ( IMapper mapper ,
31
37
IDocumentRepository documentRepository ,
@@ -34,6 +40,7 @@ public ControllingMemberCrcAppManager(IMapper mapper,
34
40
IMainFileStorageService mainFileService ,
35
41
ITransientFileStorageService transientFileService ,
36
42
IControllingMemberCrcRepository controllingMemberCrcRepository ,
43
+ IApplicationInviteRepository applicationInviteRepository ,
37
44
ILicAppRepository licAppRepository ) : base (
38
45
mapper ,
39
46
documentRepository ,
@@ -44,10 +51,24 @@ public ControllingMemberCrcAppManager(IMapper mapper,
44
51
licAppRepository )
45
52
{
46
53
_controllingMemberCrcRepository = controllingMemberCrcRepository ;
54
+ _applicationInviteRepository = applicationInviteRepository ;
47
55
}
48
56
#region anonymous new
49
57
public async Task < ControllingMemberCrcAppCommandResponse > Handle ( ControllingMemberCrcAppNewCommand cmd , CancellationToken ct )
50
58
{
59
+ ApplicationInviteResult ? invite = null ;
60
+ //check if invite is still valid
61
+ if ( cmd . ControllingMemberCrcAppSubmitRequest ? . InviteId != null )
62
+ {
63
+ var invites = await _applicationInviteRepository . QueryAsync (
64
+ new ApplicationInviteQuery ( )
65
+ {
66
+ FilterBy = new AppInviteFilterBy ( null , null , AppInviteId : cmd . ControllingMemberCrcAppSubmitRequest . InviteId )
67
+ } , ct ) ;
68
+ invite = invites . ApplicationInvites . FirstOrDefault ( ) ;
69
+ if ( invite != null && ( invite . Status == ApplicationInviteStatusEnum . Completed || invite . Status == ApplicationInviteStatusEnum . Cancelled || invite . Status == ApplicationInviteStatusEnum . Expired ) )
70
+ throw new ArgumentException ( "Invalid Invite status." ) ;
71
+ }
51
72
52
73
ControllingMemberCrcAppSubmitRequest request = cmd . ControllingMemberCrcAppSubmitRequest ;
53
74
ValidateFilesForNewApp ( cmd ) ;
@@ -60,8 +81,19 @@ public async Task<ControllingMemberCrcAppCommandResponse> Handle(ControllingMemb
60
81
61
82
await UploadNewDocsAsync ( request . DocumentExpiredInfos , cmd . LicAppFileInfos , response . ControllingMemberCrcAppId , response . ContactId , null , null , null , null , null , ct ) ;
62
83
84
+ //
63
85
await _licAppRepository . CommitLicenceApplicationAsync ( response . ControllingMemberCrcAppId , ApplicationStatusEnum . Submitted , ct ) ;
64
86
87
+ //inactivate invite
88
+ if ( cmd . ControllingMemberCrcAppSubmitRequest ? . InviteId != null )
89
+ {
90
+ await _applicationInviteRepository . ManageAsync (
91
+ new ApplicationInviteUpdateCmd ( )
92
+ {
93
+ ApplicationInviteId = ( Guid ) cmd . ControllingMemberCrcAppSubmitRequest . InviteId ,
94
+ ApplicationInviteStatusEnum = ApplicationInviteStatusEnum . Completed
95
+ } , ct ) ;
96
+ }
65
97
return new ControllingMemberCrcAppCommandResponse
66
98
{
67
99
ControllingMemberAppId = response . ControllingMemberCrcAppId ,
0 commit comments