private async Task <Domain.Document.Document> Generate(INodeServices nodeServices, RegistrationPDFData data, Letter letter, string htmlFilePath, string moduleCode, int userId) { try { var htmlString = string.Join(" ", System.IO.File.ReadAllLines(htmlFilePath)); htmlString = buildCSS(htmlString); var pdfPath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}js{Path.DirectorySeparatorChar}pdf"; var result = await nodeServices.InvokeAsync <byte[]> (pdfPath, htmlString, data); var relativeDirectory = $"{Path.DirectorySeparatorChar}{moduleCode}{Path.DirectorySeparatorChar}{data.tempFolderName}"; var directory = $"{_rootUrl}{relativeDirectory}"; var filePath = $"{relativeDirectory}{Path.DirectorySeparatorChar}{data.fileName}"; await FileHelper.SaveFileAsync(directory, data.fileName, result); Domain.Document.Document docEntity = new Domain.Document.Document() { ModuleDocumentID = letter.ModuleDocumentID, FilePath = filePath, FileType = "application/pdf", ReferenceID = data.maId, CreatedBy = userId, UpdatedBy = userId }; await _documentService.CreateOrUpdateAsync(docEntity, true, ds => ds.FilePath == docEntity.FilePath); return(docEntity); } catch (Exception ex) { _logger.Log(ex); } return(null); }
public async Task GeneratePDFDocument(string htmlFilePath, ImportStatusLog ipermit, INodeServices nodeServices, string documenttypeCode, string submoduleCode, ImportPermit iipermit) { try { var letterHeading = await _letterHeadingService.GetAsync(1); var letter = (await _letterService.GetAsync(x => x.ModuleDocument.DocumentType.DocumentTypeCode == documenttypeCode && x.ModuleDocument.Submodule.SubmoduleCode == submoduleCode)); var moduleDocument = await _moduleDocumentService.GetAsync(letter.ModuleDocumentID); var moduleCode = moduleDocument.Submodule.Module.ModuleCode; IpermitPDFData data = new IpermitPDFData(iipermit, letterHeading, letter, ipermit.Comment); var ipemitStatues = (await _statusService.GetIPermitStatus(iipermit.ID)); data.submissionDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "RQST")?.CreatedDate.ToString(); data.approvedDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "APR")?.CreatedDate.ToString(); data.rejectedDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.CreatedDate.ToString(); data.expiryDate = iipermit.ExpiryDate?.ToString();; data.reason = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.Comment; var htmlString = string.Join(" ", System.IO.File.ReadAllLines(htmlFilePath)); htmlString = buildCSS(htmlString); var pdfPath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}js{Path.DirectorySeparatorChar}pdf"; var result = await nodeServices.InvokeAsync <byte[]> (pdfPath, htmlString, data); var relativeDirectory = $"{Path.DirectorySeparatorChar}{moduleCode}{Path.DirectorySeparatorChar}{data.tempFolderName}"; var directory = $"{_rootUrl}{relativeDirectory}"; var filePath = $"{relativeDirectory}{Path.DirectorySeparatorChar}{data.fileName}"; await FileHelper.SaveFileAsync(directory, data.fileName, result); Domain.Document.Document docEntity = new Domain.Document.Document() { ModuleDocumentID = letter.ModuleDocumentID, FilePath = filePath, FileType = "application/pdf", ReferenceID = ipermit.ID, CreatedBy = ipermit.ChangedBy, UpdatedBy = ipermit.ChangedBy }; await _documentService.CreateOrUpdateAsync(docEntity, true, r => r.ModuleDocumentID == docEntity.ModuleDocumentID && r.FilePath == docEntity.FilePath && r.ReferenceID == docEntity.ReferenceID); } catch (Exception ex) { _logger.Log(ex); } }
public async Task <bool> RePrintMA(int maID, int userID) { var ma = (await _maService.FindByAsync(x => x.ID == maID)).FirstOrDefault(); Domain.Document.Document document = null; if ((bool)ma?.IsNotificationType && ma?.MAStatus.MAStatusCode == "APR") { document = await _generateDocument.GenerateRegistrationPDFDocument(_nodeServices, ma.ID, "NOTAPR", userID); } else { document = await _generateDocument.GenerateRegistrationPDFDocument(_nodeServices, ma.ID, ma.MAStatus.MAStatusCode, userID); } var log = new PrintLog() { PrintedByUserID = userID, DocumentID = document.ID, PrintedDate = DateTime.Now }; return(await _printLog.CreateAsync(log)); }