public CustomFileDetails GetTemplatedLicenseForPreview(List <SectionsWithClauses> model, int orgId, int schemaId, LoggedInUserDetails user)
        {
            // Check access
            _security.CheckBasicAccess(user);

            // Check whether organisation is active
            if (!user.Organization.IsActive)
            {
                throw new BaseException("Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Define result
            var result = new CustomFileDetails();

            // Get published license template
            var template = _licenseTemplates.FirstOrDefault(i => i.Status == (int)TemplateStatus.Active);

            // Get schema file
            var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == schemaId);

            // Setup url to download schema
            var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID);

            // Setup content for document
            var document = _licenseContentBuilder.GetDocument(model, schemaId, orgId, template, _config.DataLinkerHost, urlToSchema);

            // Create pdf document
            var pdfDocument = new HtmlToPdfConverter
            {
                PageFooterHtml = _licenseContentBuilder.GetFooterText((int)PublishStatus.Draft, _config.DataLinkerHost)
            };

            // Get bytes from document
            var bytes = pdfDocument.GeneratePdf(document.OuterXml);

            // Setup result
            result.Content  = bytes;
            result.MimeType = "application/pdf";
            result.FileName = $"{template.Name}.pdf";

            // Return result
            return(result);
        }
Пример #2
0
        public void LicenseIsPendingApproval(int userId,
                                             string linkToConfirmScreen,
                                             string linkToSchema,
                                             string linkToDataLinker,
                                             string schemaName,
                                             int licenseId)
        {
            var license         = _licenseService.FirstOrDefault(i => i.ID == licenseId);
            var application     = _applicationService.FirstOrDefault(i => i.ID == license.ApplicationID);
            var organization    = _organizationService.FirstOrDefault(i => i.ID == application.OrganizationID);
            var template        = _licenseTemplateService.FirstOrDefault(i => i.ID == license.LicenseTemplateID.Value);
            var licenseDocument = _licenseContentBuilder.GetLicenseContent(license.ID);

            _licenseContentBuilder.InsertLicenseDetails(licenseDocument, linkToSchema, linkToDataLinker, organization.ID, application.IsProvider);
            var pdfDocument = new HtmlToPdfConverter {
                PageFooterHtml = _licenseContentBuilder.GetFooterText(license.Status, linkToDataLinker)
            };
            var pdfBytes   = pdfDocument.GeneratePdf(licenseDocument.OuterXml);
            var stream     = new MemoryStream(pdfBytes);
            var attachment = new List <Attachment>
            {
                new Attachment(stream, $"{template.Name}{MailFileFormat}",
                               MediaTypeNames.Application.Pdf)
            };

            var user = _userService.FirstOrDefault(i => i.ID == userId);

            if (user != null)
            {
                var email = new LegalOfficerVerificationLicenseEmail
                {
                    To   = user.Email,
                    From = _emailSettings.SmtpFromEmail,
                    Name = user.Name,
                    LinkToConfirmationScreen = linkToConfirmScreen,
                    OrganizationName         = organization.Name,
                    SchemaName  = schemaName,
                    IsProvider  = application.IsProvider,
                    Attachments = attachment
                };

                Send(email);
            }
        }