@@ -12,29 +12,27 @@ namespace DigitalLearningSolutions.Web.Services
1212 using DigitalLearningSolutions . Data . Exceptions ;
1313 using DigitalLearningSolutions . Data . Helpers ;
1414 using DigitalLearningSolutions . Data . Models . Frameworks . Import ;
15- using DigitalLearningSolutions . Web . Models ;
16- using Microsoft . AspNetCore . Http ;
1715
1816 public interface IImportCompetenciesFromFileService
1917 {
20- byte [ ] GetCompetencyFileForFramework ( int frameworkId , bool v ) ;
21- public ImportCompetenciesResult PreProcessCompetenciesTable ( IXLWorkbook workbook ) ;
22- public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId ) ;
18+ byte [ ] GetCompetencyFileForFramework ( int frameworkId , bool isBlank , string vocabulary ) ;
19+ public ImportCompetenciesResult PreProcessCompetenciesTable ( IXLWorkbook workbook , string vocabulary ) ;
20+ public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary ) ;
2321 }
2422 public class ImportCompetenciesFromFileService : IImportCompetenciesFromFileService
2523 {
2624 private readonly IFrameworkService frameworkService ;
2725 private static readonly XLTableTheme TableTheme = XLTableTheme . TableStyleLight9 ;
28- public const string CompetenciesSheetName = "CompetenciesBulkUpload " ;
26+ public const string CompetenciesSheetName = "FrameworkBulkUpload " ;
2927 public ImportCompetenciesFromFileService (
3028 IFrameworkService frameworkService
3129 )
3230 {
3331 this . frameworkService = frameworkService ;
3432 }
35- public ImportCompetenciesResult PreProcessCompetenciesTable ( IXLWorkbook workbook )
33+ public ImportCompetenciesResult PreProcessCompetenciesTable ( IXLWorkbook workbook , string vocabulary )
3634 {
37- var table = OpenCompetenciesTable ( workbook ) ;
35+ var table = OpenCompetenciesTable ( workbook , vocabulary ) ;
3836 var competencyRows = table . Rows ( ) . Skip ( 1 ) . Select ( row => new CompetencyTableRow ( table , row ) ) . ToList ( ) ;
3937 foreach ( var competencyRow in competencyRows )
4038 {
@@ -54,14 +52,14 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow)
5452 competencyRow . RowStatus = RowStatus . CompetencyUpdated ;
5553 }
5654 }
57- public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId )
55+ public ImportCompetenciesResult ProcessCompetenciesFromFile ( IXLWorkbook workbook , int adminUserId , int frameworkId , string vocabulary )
5856 {
5957 int maxFrameworkCompetencyId = frameworkService . GetMaxFrameworkCompetencyID ( ) ;
6058 int maxFrameworkCompetencyGroupId = frameworkService . GetMaxFrameworkCompetencyGroupID ( ) ;
61- var table = OpenCompetenciesTable ( workbook ) ;
59+ var table = OpenCompetenciesTable ( workbook , vocabulary ) ;
6260 return ProcessCompetenciesTable ( table , adminUserId , frameworkId , maxFrameworkCompetencyId , maxFrameworkCompetencyGroupId ) ;
6361 }
64- internal IXLTable OpenCompetenciesTable ( IXLWorkbook workbook )
62+ internal IXLTable OpenCompetenciesTable ( IXLWorkbook workbook , string vocabulary )
6563 {
6664 var worksheet = workbook . Worksheet ( 1 ) ;
6765 worksheet . Columns ( 1 , 15 ) . Unhide ( ) ;
@@ -70,7 +68,7 @@ internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook)
7068 throw new InvalidHeadersException ( ) ;
7169 }
7270 var table = worksheet . Tables . Table ( 0 ) ;
73- if ( ! ValidateHeaders ( table ) )
71+ if ( ! ValidateHeaders ( table , vocabulary ) )
7472 {
7573 throw new InvalidHeadersException ( ) ;
7674 }
@@ -132,26 +130,26 @@ CompetencyTableRow competencyRow
132130 return maxFrameworkCompetencyGroupId ;
133131 }
134132
135- private static bool ValidateHeaders ( IXLTable table )
133+ private static bool ValidateHeaders ( IXLTable table , string Vocabulary )
136134 {
137135 var expectedHeaders = new List < string >
138136 {
139137 "ID" ,
140- "CompetencyGroup ",
138+ Vocabulary + "Group ",
141139 "GroupDescription" ,
142- "Competency" ,
143- "CompetencyDescription ",
140+ Vocabulary ,
141+ Vocabulary + "Description ",
144142 "AlwaysShowDescription" ,
145143 "FlagsCSV"
146144 } . OrderBy ( x => x ) ;
147145 var actualHeaders = table . Fields . Select ( x => x . Name ) . OrderBy ( x => x ) ;
148146 return actualHeaders . SequenceEqual ( expectedHeaders ) ;
149147 }
150148
151- public byte [ ] GetCompetencyFileForFramework ( int frameworkId , bool blank )
149+ public byte [ ] GetCompetencyFileForFramework ( int frameworkId , bool blank , string vocabulary )
152150 {
153151 using var workbook = new XLWorkbook ( ) ;
154- PopulateCompetenciesSheet ( workbook , frameworkId , blank ) ;
152+ PopulateCompetenciesSheet ( workbook , frameworkId , blank , vocabulary ) ;
155153 if ( blank )
156154 {
157155 ClosedXmlHelper . HideWorkSheetColumn ( workbook , "ID" ) ;
@@ -167,7 +165,7 @@ public byte[] GetCompetencyFileForFramework(int frameworkId, bool blank)
167165 workbook . SaveAs ( stream ) ;
168166 return stream . ToArray ( ) ;
169167 }
170- private void PopulateCompetenciesSheet ( IXLWorkbook workbook , int frameworkId , bool blank )
168+ private void PopulateCompetenciesSheet ( IXLWorkbook workbook , int frameworkId , bool blank , string vocabulary )
171169 {
172170
173171
@@ -184,8 +182,10 @@ private void PopulateCompetenciesSheet(IXLWorkbook workbook, int frameworkId, bo
184182 FlagsCSV = x . FlagsCsv ,
185183 }
186184 ) ;
187-
188185 ClosedXmlHelper . AddSheetToWorkbook ( workbook , CompetenciesSheetName , competencies , TableTheme ) ;
186+ ClosedXmlHelper . RenameWorksheetColumn ( workbook , "CompetencyGroup" , vocabulary + "Group" ) ;
187+ ClosedXmlHelper . RenameWorksheetColumn ( workbook , "Competency" , vocabulary ) ;
188+ ClosedXmlHelper . RenameWorksheetColumn ( workbook , "CompetencyDescription" , vocabulary + "Description" ) ;
189189 }
190190 }
191191}
0 commit comments