@@ -138,16 +138,39 @@ public async Task ProcessAppWithSharableClearanceAsync(ApplicationCreateCmd crea
138
138
if ( ! createApplicationCmd . SharedClearanceId . HasValue )
139
139
throw new ArgumentException ( "SharedClearanceId cannot be null" ) ;
140
140
account ? org = await _context . GetOrgById ( createApplicationCmd . OrgId , ct ) ;
141
- spd_clearance ? clearance = await _context . GetClearanceById ( ( Guid ) createApplicationCmd . SharedClearanceId , ct ) ;
142
141
contact ? contact = await _context . contacts . Where ( c => c . contactid == createApplicationCmd . ContactId ) . FirstOrDefaultAsync ( ct ) ;
143
142
_mapper . Map < ApplicationCreateCmd , contact > ( createApplicationCmd , contact ) ;
144
143
_context . UpdateObject ( contact ) ;
145
144
146
- Guid teamGuid = Guid . Parse ( DynamicsConstants . Screening_Risk_Assessment_Coordinator_Team_Guid ) ;
147
- team ? team = await _context . teams . Where ( t => t . teamid == teamGuid ) . FirstOrDefaultAsync ( ct ) ;
145
+ //spdbt-3220
146
+ spd_clearance ? clearance = await _context . spd_clearances
147
+ . Expand ( c => c . spd_CaseID )
148
+ . Where ( c => c . spd_clearanceid == ( Guid ) createApplicationCmd . SharedClearanceId )
149
+ . FirstOrDefaultAsync ( ct ) ;
150
+ if ( clearance == null )
151
+ throw new ApiException ( HttpStatusCode . BadRequest , "Cannot find specified clearance." ) ;
152
+ team ? team = null ;
153
+ int state ;
154
+ int status ;
155
+ if ( clearance . spd_CaseID . spd_risklevel == ( int ) CaseRiskLevelOptionSet . L2 || clearance . spd_CaseID . spd_risklevel == ( int ) CaseRiskLevelOptionSet . L3 )
156
+ {
157
+ Guid teamGuid = Guid . Parse ( DynamicsConstants . Screening_Risk_Assessment_Coordinator_Team_Guid ) ;
158
+ team = await _context . teams . Where ( t => t . teamid == teamGuid ) . FirstOrDefaultAsync ( ct ) ;
159
+ status = ( int ) ClearanceAccessStatusOptionSet . Draft ;
160
+ state = DynamicsConstants . StateCode_Active ;
161
+ }
162
+ else
163
+ {
164
+ Guid teamGuid = Guid . Parse ( DynamicsConstants . Client_Service_Team_Guid ) ;
165
+ team = await _context . teams . Where ( t => t . teamid == teamGuid ) . FirstOrDefaultAsync ( ct ) ;
166
+ status = ( int ) ClearanceAccessStatusOptionSet . Approved ;
167
+ state = DynamicsConstants . StateCode_Active ;
168
+ }
169
+
148
170
spd_clearanceaccess clearanceaccess = new ( ) { spd_clearanceaccessid = Guid . NewGuid ( ) } ;
149
- clearanceaccess . statecode = DynamicsConstants . StateCode_Active ;
150
- clearanceaccess . statuscode = ( int ) ClearanceAccessStatusOptionSet . Draft ;
171
+ clearanceaccess . statecode = state ;
172
+ clearanceaccess . statuscode = status ;
173
+ clearanceaccess . spd_issystemgenerated = true ;
151
174
_context . AddTospd_clearanceaccesses ( clearanceaccess ) ;
152
175
_context . SetLink ( clearanceaccess , nameof ( clearanceaccess . spd_OrganizationId ) , org ) ;
153
176
_context . SetLink ( clearanceaccess , nameof ( clearanceaccess . spd_ClearanceId ) , clearance ) ;
0 commit comments