public async Task <DocumentDetails> CreateDocument(string templateName, string mappingName, DocumentPayload payload) { var template = repository.GetLatestTemplate(templateName); Stream mappingBytes = null; if (mappingName != null) { var mapping = repository.GetLatestMapping(templateName, null, mappingName); mappingBytes = mapping.Buffer; } var documentBytes = CreateDocument(template.Buffer, mappingBytes, payload); var document = await repository.CreateDocument(templateName, mappingName, documentBytes); if (htmlRepository != null) { var pageTitle = template.Name; var conversion = OpenXmlWordConverter.ConvertToHtml(document.Buffer, pageTitle, document.Name); htmlRepository.SaveHtml(document.Name, conversion.Html, conversion.Images); } return(TransformFull(document)); }
public async Task <TemplateDetails> CreateTemplate(TemplateData templateData, Stream bytes) { templateData = templateData ?? throw new ArgumentNullException(nameof(templateData)); var templateName = templateData.TemplateName ?? throw new ArgumentNullException(nameof(templateData.TemplateName)); IEnumerable <TemplateField> fields; try { fields = OpenXmlWordProcessing.FindTemplateFields(bytes); } catch (FileFormatException) { throw new ArgumentException(nameof(bytes)); } var content = await repository.CreateTemplate(templateName, bytes); if (htmlRepository != null) { var conversion = OpenXmlWordConverter.ConvertToHtml(bytes, content.Name); htmlRepository.SaveHtml(content.Name, null, conversion.Images); } return(TransformFull(content, fields)); }