1- using AutoMapper ;
2- using ECER . Utilities . DataverseSdk . Model ;
3- using ECER . Utilities . ObjectStorage . Providers ;
1+ using ECER . Utilities . DataverseSdk . Model ;
42using ECER . Utilities . ObjectStorage . Providers . S3 ;
53using Microsoft . Extensions . Configuration ;
6- using System ;
7- using System . Collections . Generic ;
8- using System . Configuration ;
9- using System . Linq ;
10- using System . Text ;
11- using System . Threading . Tasks ;
4+ using Microsoft . Xrm . Sdk . Client ;
125
136namespace ECER . Resources . Documents . ICRA ;
147
158internal sealed partial class ICRARepository
169{
17- private async Task UpdateInternationalCertifications ( ecer_Application application , Contact contact , string ApplicantId , List < InternationalCertification > updatedEntities , CancellationToken ct )
10+ private async Task UpdateInternationalCertifications ( ecer_ICRAEligibilityAssessment icraEligibility , Contact contact , string ApplicantId , List < InternationalCertification > updatedEntities , CancellationToken ct )
1811 {
1912 await Task . CompletedTask ;
2013
21- var existingInternationalCertifications = context . ecer_InternationalCertificationSet . Where ( t => t . ecer_Applicationid . Id == application . Id ) . ToList ( ) ;
14+ var existingInternationalCertifications = context . ecer_InternationalCertificationSet . Where ( t => t . ecer_EligibilityAssessment . Id == icraEligibility . Id ) . ToList ( ) ;
2215 foreach ( var InternationalCertification in existingInternationalCertifications )
2316 {
2417 if ( ! updatedEntities . Any ( t => t . Id == InternationalCertification . Id . ToString ( ) ) )
2518 {
26- // This deletes all files and document urls before deleting the professional development object
19+ // This deletes all files and document urls before deleting the international certifications object
2720 await DeleteFilesForInternationalCertification ( InternationalCertification . ecer_InternationalCertificationId , Guid . Parse ( ApplicantId ) , ct ) ;
2821 context . DeleteObject ( InternationalCertification ) ;
2922 }
3023 }
3124
32- // Update Existing Professional Developments
25+ // Update existing International Certifications
3326 foreach ( var InternationalCertification in updatedEntities . Where ( d => ! string . IsNullOrEmpty ( d . Id ) ) )
3427 {
3528 var oldInternationalCertification = existingInternationalCertifications . SingleOrDefault ( t => t . Id . ToString ( ) == InternationalCertification . Id ) ;
@@ -49,15 +42,11 @@ private async Task UpdateInternationalCertifications(ecer_Application applicatio
4942 foreach ( var InternationalCertification in updatedEntities . Where ( d => string . IsNullOrEmpty ( d . Id ) ) )
5043 {
5144 var ecerInternationalCertification = mapper . Map < ecer_InternationalCertification > ( InternationalCertification ) ! ;
52- if ( application . StatusCode == ecer_Application_StatusCode . Draft )
53- {
54- ecerInternationalCertification . StatusCode = ecer_InternationalCertification_StatusCode . Draft ;
55- }
45+ // no draft status handling required here beyond default mapping
5646 var newId = Guid . NewGuid ( ) ;
5747 ecerInternationalCertification . ecer_InternationalCertificationId = newId ;
5848 context . AddObject ( ecerInternationalCertification ) ;
59- context . AddLink ( application , ecer_Application . Fields . ecer_ecer_InternationalCertification_Applicationi , ecerInternationalCertification ) ;
60- context . AddLink ( contact , Contact . Fields . ecer_ecer_InternationalCertification_Applicantid_ , ecerInternationalCertification ) ;
49+ context . AddLink ( icraEligibility , ecer_ICRAEligibilityAssessment . Fields . ecer_internationalcertification_EligibilityAssessment_ecer_icraeligibilityassessment , ecerInternationalCertification ) ;
6150 await HandleInternationalCertificationFiles ( ecerInternationalCertification , Guid . Parse ( ApplicantId ) , InternationalCertification . NewFiles , InternationalCertification . DeletedFiles , ct ) ;
6251 }
6352 }
@@ -108,7 +97,7 @@ private async Task HandleAddedFiles(ecer_InternationalCertification Internationa
10897 throw new InvalidOperationException ( $ "InternationalCertification '{ InternationalCertification } ' not found") ;
10998 }
11099 // add file and create document url
111- // link it to professional development
100+ // link it to international certification
112101 await AddFilesForInternationalCertification ( InternationalCertification , applicantId , new List < string > ( ) { fileId } , ct ) ;
113102 }
114103 }
@@ -117,7 +106,7 @@ private async Task DeleteFilesForInternationalCertification(Guid? InternationalC
117106 {
118107 await Task . CompletedTask ;
119108
120- var files = context . bcgov_DocumentUrlSet . Where ( d => d . ecer_bcgov_documenturl_InternationalCertificationId . ecer_InternationalCertificationId == InternationalCertificationId && d . bcgov_contact_bcgov_documenturl . ContactId == applicantId ) . ToList ( ) ;
109+ var files = context . bcgov_DocumentUrlSet . Where ( d => d . ecer_bcgov_documenturl_internationalcertificationid . ecer_InternationalCertificationId == InternationalCertificationId && d . bcgov_contact_bcgov_documenturl . ContactId == applicantId ) . ToList ( ) ;
121110 for ( int i = 0 ; i < files . Count ; i ++ )
122111 {
123112 var items = files [ i ] . bcgov_Url . Split ( '/' ) ;
@@ -160,7 +149,7 @@ private async Task AddFilesForInternationalCertification(ecer_InternationalCerti
160149
161150 context . AddObject ( documenturl ) ;
162151 context . AddLink ( documenturl , bcgov_DocumentUrl . Fields . bcgov_contact_bcgov_documenturl , applicant ) ;
163- context . AddLink ( documenturl , bcgov_DocumentUrl . Fields . ecer_bcgov_documenturl_InternationalCertificationId , InternationalCertification ) ;
152+ context . AddLink ( documenturl , bcgov_DocumentUrl . Fields . ecer_bcgov_documenturl_internationalcertificationid , InternationalCertification ) ;
164153 }
165154 }
166155
0 commit comments