@@ -20,6 +20,7 @@ public interface IImportCompetenciesFromFileService
2020 byte [ ] GetCompetencyFileForFramework ( int frameworkId , bool isBlank , string vocabulary ) ;
2121 public ImportCompetenciesResult PreProcessCompetenciesTable ( IXLWorkbook workbook , string vocabulary , int frameworkId ) ;
2222 public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary , int reorderCompetenciesOption , int addAssessmentQuestionsOption , int customAssessmentQuestionID , List < int > defaultQuestionIds ) ;
23+ public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary , int reorderCompetenciesOption , int addAssessmentQuestionsOption , int customAssessmentQuestionID , List < int > defaultQuestionIds ) ;
2324 }
2425 public class ImportCompetenciesFromFileService : IImportCompetenciesFromFileService
2526 {
@@ -71,11 +72,12 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int>
7172 competencyRow . Validate ( ) ;
7273 }
7374 public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary , int reorderCompetenciesOption , int addAssessmentQuestionsOption , int customAssessmentQuestionID , List < int > defaultQuestionIds )
75+ public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary , int reorderCompetenciesOption , int addAssessmentQuestionsOption , int customAssessmentQuestionID , List < int > defaultQuestionIds )
7476 {
7577 int maxFrameworkCompetencyId = frameworkService . GetMaxFrameworkCompetencyID ( ) ;
7678 int maxFrameworkCompetencyGroupId = frameworkService . GetMaxFrameworkCompetencyGroupID ( ) ;
7779 var table = OpenCompetenciesTable ( workbook , vocabulary ) ;
78- return ProcessCompetenciesTable ( table , adminUserId , frameworkId , maxFrameworkCompetencyId , maxFrameworkCompetencyGroupId , addAssessmentQuestionsOption , reorderCompetenciesOption , customAssessmentQuestionID , defaultQuestionIds ) ;
80+ return ProcessCompetenciesTable ( table , adminUserId , frameworkId , maxFrameworkCompetencyId , maxFrameworkCompetencyGroupId , addAssessmentQuestionsOption , customAssessmentQuestionID , defaultQuestionIds ) ;
7981 }
8082 internal IXLTable OpenCompetenciesTable ( IXLWorkbook workbook , string vocabulary )
8183 {
@@ -92,7 +94,7 @@ internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook, string vocabulary)
9294 }
9395 return table ;
9496 }
95- internal ImportCompetenciesResult ProcessCompetenciesTable ( IXLTable table , int adminUserId , int frameworkId , int maxFrameworkCompetencyId , int maxFrameworkCompetencyGroupId , int addAssessmentQuestionsOption , int reorderCompetenciesOption , int customAssessmentQuestionID , List < int > defaultQuestionIds )
97+ internal ImportCompetenciesResult ProcessCompetenciesTable ( IXLTable table , int adminUserId , int frameworkId , int maxFrameworkCompetencyId , int maxFrameworkCompetencyGroupId , int addAssessmentQuestionsOption , int customAssessmentQuestionID , List < int > defaultQuestionIds )
9698 {
9799 var competenciesRows = table . Rows ( ) . Skip ( 1 ) . Select ( row => new CompetencyTableRow ( table , row ) ) . ToList ( ) ;
98100 int rowCount = 0 ;
@@ -120,7 +122,7 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
120122 . Count ( ) ;
121123 foreach ( var competencyRow in competenciesRows )
122124 {
123- maxFrameworkCompetencyGroupId = ProcessCompetencyRow ( adminUserId , frameworkId , maxFrameworkCompetencyId , maxFrameworkCompetencyGroupId , addAssessmentQuestionsOption , reorderCompetenciesOption , customAssessmentQuestionID , defaultQuestionIds , competencyRow ) ;
125+ maxFrameworkCompetencyGroupId = ProcessCompetencyRow ( adminUserId , frameworkId , maxFrameworkCompetencyId , maxFrameworkCompetencyGroupId , addAssessmentQuestionsOption , customAssessmentQuestionID , defaultQuestionIds , competencyRow ) ;
124126 }
125127 // Check for changes to competency group order and apply them if appropriate:
126128 if ( reorderCompetenciesOption == 2 )
@@ -159,7 +161,6 @@ private int ProcessCompetencyRow(
159161 int maxFrameworkCompetencyId ,
160162 int maxFrameworkCompetencyGroupId ,
161163 int addAssessmentQuestionsOption ,
162- int reorderCompetenciesOption ,
163164 int customAssessmentQuestionID ,
164165 List < int > defaultQuestionIds ,
165166 CompetencyTableRow competencyRow
@@ -169,13 +170,13 @@ CompetencyTableRow competencyRow
169170 {
170171 return maxFrameworkCompetencyGroupId ;
171172 }
173+ int newCompetencyGroupId = 0 ;
172174 int newCompetencyId = 0 ;
173- int newFrameworkCompetencyId = 0 ;
174175 //If competency group is set, check if competency group exists within framework and add if not and get the Framework Competency Group ID
175- int ? frameworkCompetencyGroupId = null ;
176+ int ? frameworkCompetencyGroupId = null ;
176177 if ( competencyRow . CompetencyGroup != null )
177178 {
178- int newCompetencyGroupId = frameworkService . InsertCompetencyGroup ( competencyRow . CompetencyGroup , competencyRow . GroupDescription , adminUserId , frameworkId ) ;
179+ newCompetencyGroupId = frameworkService . InsertCompetencyGroup ( competencyRow . CompetencyGroup , competencyRow . GroupDescription , adminUserId ) ;
179180 if ( newCompetencyGroupId > 0 )
180181 {
181182 frameworkCompetencyGroupId = frameworkService . InsertFrameworkCompetencyGroup ( newCompetencyGroupId , frameworkId , adminUserId ) ;
@@ -193,10 +194,10 @@ CompetencyTableRow competencyRow
193194 if ( frameworkCompetency != null )
194195 {
195196 newCompetencyId = frameworkCompetency . CompetencyID ;
196- if ( frameworkCompetency . Name != competencyRow . Competency || frameworkCompetency . Description != competencyRow . CompetencyDescription || frameworkCompetency . AlwaysShowDescription != competencyRow . AlwaysShowDescription )
197+ if ( frameworkCompetency . Name != competencyRow . Competency || frameworkCompetency . Description != competencyRow . CompetencyDescription || frameworkCompetency . AlwaysShowDescription != competencyRow . AlwaysShowDescription )
197198 {
198199 frameworkService . UpdateFrameworkCompetency ( ( int ) competencyRow . ID , competencyRow . Competency , competencyRow . CompetencyDescription , adminUserId , competencyRow . AlwaysShowDescription ?? false ) ;
199- competencyRow . RowStatus = ( competencyRow . RowStatus == RowStatus . CompetencyGroupInserted ? RowStatus . CompetencyGroupAndCompetencyUpdated : RowStatus . CompetencyUpdated ) ;
200+ competencyRow . RowStatus = ( competencyRow . RowStatus == RowStatus . CompetencyGroupInserted ? RowStatus . CompetencyGroupAndCompetencyUpdated : RowStatus . CompetencyUpdated ) ;
200201 }
201202 else
202203 {
@@ -210,7 +211,7 @@ CompetencyTableRow competencyRow
210211 newCompetencyId = frameworkService . InsertCompetency ( competencyRow . Competency , competencyRow . CompetencyDescription , adminUserId ) ;
211212 if ( newCompetencyId > 0 )
212213 {
213- newFrameworkCompetencyId = frameworkService . InsertFrameworkCompetency ( newCompetencyId , frameworkCompetencyGroupId , adminUserId , frameworkId , competencyRow . AlwaysShowDescription ?? false ) ; //including always show desc flag
214+ var newFrameworkCompetencyId = frameworkService . InsertFrameworkCompetency ( newCompetencyId , frameworkCompetencyGroupId , adminUserId , frameworkId , competencyRow . AlwaysShowDescription ?? false ) ; //including always show desc flag
214215 if ( newFrameworkCompetencyId > maxFrameworkCompetencyId )
215216 {
216217 competencyRow . RowStatus = ( competencyRow . RowStatus == RowStatus . CompetencyGroupInserted ? RowStatus . CompetencyGroupAndCompetencyInserted : RowStatus . CompetencyInserted ) ;
@@ -224,12 +225,11 @@ CompetencyTableRow competencyRow
224225
225226
226227 // If flags are supplied, add them:
227- if ( ! string . IsNullOrWhiteSpace ( competencyRow . FlagsCsv . Trim ( ) ) )
228+ if ( competencyRow . FlagsCsv != null )
228229 {
229230 var flags = competencyRow . FlagsCsv . Split ( ',' ) ;
230- var flagIds = new List < int > ( ) ;
231- foreach ( var flag in flags )
232- {
231+ int [ ] flagIds = [ ] ;
232+ foreach ( var flag in flags ) {
233233 int flagId = 0 ;
234234 var frameworkFlags = frameworkService . GetCompetencyFlagsByFrameworkId ( frameworkId , null , null ) ;
235235 if ( frameworkFlags . Any ( ) )
@@ -239,64 +239,37 @@ CompetencyTableRow competencyRow
239239 if ( frameworkFlag . FlagName == flag )
240240 {
241241 flagId = frameworkFlag . FlagId ;
242- break ;
243242 }
244243 }
245244 }
246245 if ( flagId == 0 )
247246 {
248247 flagId = frameworkService . AddCustomFlagToFramework ( frameworkId , flag , "Flag" , "nhsuk-tag--white" ) ;
249248 }
250- flagIds . Add ( flagId ) ;
249+ flagIds . Append ( flagId ) ;
251250 }
252- if ( flagIds . Count > 0 )
253- {
254- var updated = frameworkService . UpdateCompetencyFlags ( frameworkId , newCompetencyId , [ .. flagIds ] ) ;
255- if ( updated > 0 && competencyRow . RowStatus == RowStatus . Skipped )
256- {
257- competencyRow . RowStatus = RowStatus . CompetencyUpdated ;
258- }
251+ if ( flagIds . Any ( ) ) {
252+ frameworkService . UpdateCompetencyFlags ( frameworkId , newCompetencyId , flagIds ) ;
259253 }
260254 }
261255
262- // Reorder competencies if required:
263- if ( reorderCompetenciesOption == 2 )
264- {
265- var frameworkCompetencyId = ( int ) competencyRow . ID ;
266- var frameworkCompetency = frameworkService . GetFrameworkCompetencyById ( frameworkCompetencyId ) ;
267- var placesToMove = Math . Abs ( frameworkCompetency . Ordering - competencyRow . CompetencyOrderNumber ) ;
268-
269- if ( placesToMove > 0 )
270- {
271- var direction = frameworkCompetency . Ordering > competencyRow . CompetencyOrderNumber ? "UP" : "DOWN" ;
272-
273- for ( int i = 0 ; i < placesToMove ; i ++ )
274- {
275- frameworkService . MoveFrameworkCompetency ( frameworkCompetencyId , true , direction ) ;
276- }
277-
278- competencyRow . Reordered = true ;
279- }
280- }
281256
282257 // Add assessment questions if necessary:
283258 if ( defaultQuestionIds . Count > 0 | customAssessmentQuestionID > 0 )
284259 {
285260 if ( competencyRow . RowStatus == RowStatus . CompetencyInserted | competencyRow . RowStatus == RowStatus . CompetencyGroupAndCompetencyInserted || addAssessmentQuestionsOption == 2 && competencyRow . RowStatus == RowStatus . CompetencyUpdated | competencyRow . RowStatus == RowStatus . CompetencyGroupAndCompetencyUpdated || addAssessmentQuestionsOption == 3 )
286261 {
287- foreach ( var id in defaultQuestionIds )
262+ foreach ( var id in defaultQuestionIds )
288263 {
289- frameworkService . AddCompetencyAssessmentQuestion ( competencyRow . ID ?? newFrameworkCompetencyId , id , adminUserId ) ;
264+ frameworkService . AddCompetencyAssessmentQuestion ( ( int ) competencyRow . ID , id , adminUserId ) ;
290265 }
291- if ( customAssessmentQuestionID > 0 )
266+ if ( customAssessmentQuestionID > 0 )
292267 {
293- frameworkService . AddCompetencyAssessmentQuestion ( competencyRow . ID ?? newFrameworkCompetencyId , customAssessmentQuestionID , adminUserId ) ;
268+ frameworkService . AddCompetencyAssessmentQuestion ( ( int ) competencyRow . ID , customAssessmentQuestionID , adminUserId ) ;
294269 }
295270 }
296271 }
297272
298-
299-
300273 return maxFrameworkCompetencyGroupId ;
301274 }
302275
0 commit comments