Skip to content

Commit 3284e0f

Browse files
TD-2865: Improve error messages when bulk upload Excel file doesn't contain correct worksheet
1 parent 2200599 commit 3284e0f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/BulkUploadController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using Microsoft.FeatureManagement.Mvc;
1515
using Microsoft.Extensions.Configuration;
1616
using ConfigurationExtensions = DigitalLearningSolutions.Data.Extensions.ConfigurationExtensions;
17+
using ClosedXML.Excel;
18+
1719
[FeatureGate(FeatureFlags.RefactoredTrackingSystem)]
1820
[Authorize(Policy = CustomPolicies.UserCentreAdmin)]
1921
[SetDlsSubApplication(nameof(DlsSubApplication.TrackingSystem))]
@@ -78,6 +80,12 @@ public IActionResult StartUpload()
7880
public IActionResult StartUpload(UploadDelegatesViewModel model)
7981
{
8082
int MaxBulkUploadRows = GetMaxBulkUploadRowsLimit();
83+
var workbook = new XLWorkbook(model.DelegatesFile.OpenReadStream());
84+
if (!workbook.Worksheets.Contains(DelegateDownloadFileService.DelegatesSheetName))
85+
{
86+
ModelState.AddModelError("MaxBulkUploadRows", CommonValidationErrorMessages.InvalidExcelValidationMessage);
87+
return View("StartUpload", model);
88+
}
8189
int ExcelRowsCount = delegateUploadFileService.GetBulkUploadExcelRowCount(model.DelegatesFile);
8290
if (ExcelRowsCount > MaxBulkUploadRows)
8391
{

DigitalLearningSolutions.Web/Helpers/CommonValidationErrorMessages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ public static class CommonValidationErrorMessages
3535
"A user with this email address is already registered";
3636
public const string CentreNameAlreadyExist = "The centre name you have entered already exists, please enter a different centre name";
3737
public const string MaxBulkUploadRowsLimit = "File must contain no more than {0} rows";
38+
public const string InvalidExcelValidationMessage = "The uploaded file must contain a \"DelegatesBulkUpload\" worksheet. Use the \"Download delegates\" button to generate a template.";
3839
}
3940
}

0 commit comments

Comments
 (0)