Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1741,13 +1741,22 @@ public async Task<IActionResult> DownloadCertificate(int candidateAssessmentId)
var pdfReportFile = await pdfService.GetPdfReportFile(pdfReportResponse);
if (pdfReportFile != null)
{
const int MaxFileNameLength = 150;
const string extension = ".pdf";
var nameTextLength = string.IsNullOrEmpty(model.CompetencySelfAssessmentCertificates.LearnerName) ? 0 : model.CompetencySelfAssessmentCertificates.LearnerName.Length;
var isPrnExist = !string.IsNullOrEmpty(model.CompetencySelfAssessmentCertificates.LearnerPRN);
var selfAssessmentName = model.CompetencySelfAssessmentCertificates.SelfAssessment ?? string.Empty;
var shortSelfAssessment = selfAssessmentName[..Math.Min(50, selfAssessmentName.Length)];
var learnerName = model.CompetencySelfAssessmentCertificates.LearnerName ?? string.Empty;
var shortLearnerName = learnerName[..Math.Min(15, learnerName.Length)];
var fileName = $"{shortSelfAssessment} - {shortLearnerName}" + (isPrnExist ? $" - {model.CompetencySelfAssessmentCertificates.LearnerPRN}.pdf" : ".pdf");
var fileName = $"Certificate - {shortSelfAssessment} - {shortLearnerName}" + (isPrnExist ? $" - {model.CompetencySelfAssessmentCertificates.LearnerPRN}" : "");
if (fileName.Length > MaxFileNameLength)
{
fileName = fileName[..MaxFileNameLength];
fileName = fileName + extension;
return File(pdfReportFile, FileHelper.GetContentTypeFromFileName(fileName), fileName);
}
fileName = fileName + extension;
return File(pdfReportFile, FileHelper.GetContentTypeFromFileName(fileName), fileName);
}
}
Expand Down
Loading