public void LicenseAgreementCreated(int licenseId, string linkToLicense, string linkToSchema, string urlToDataLinker) { var agreement = _agreementService.FirstOrDefault(i => i.ID == licenseId); var consumerRegistration = _consumerProviderRegistrations.GetById(agreement.ConsumerProviderRegistrationId); var providerLicense = _licenseService.FirstOrDefault(i => i.ID == consumerRegistration.OrganizationLicenseID); var consumerApp = _applicationService.FirstOrDefault(i => i.ID == consumerRegistration.ConsumerApplicationID); var consumerOrganization = _organizationService.FirstOrDefault(i => i.ID == consumerApp.OrganizationID); var providerApp = _applicationService.FirstOrDefault(i => i.ID == providerLicense.ApplicationID); var providerOrganization = _organizationService.FirstOrDefault(i => i.ID == providerApp.OrganizationID); var dataSchema = _dataSchemaService.FirstOrDefault(i => i.ID == providerLicense.DataSchemaID); var users = _userService.Where(i => i.OrganizationID == consumerOrganization.ID).Where(i => i.IsActive == true && i.IsIntroducedAsLegalOfficer == true && i.IsVerifiedAsLegalOfficer == true).ToList(); var providerLegals = _userService.Where(i => i.OrganizationID == providerOrganization.ID).Where(i => i.IsActive == true && i.IsIntroducedAsLegalOfficer == true && i.IsVerifiedAsLegalOfficer == true); users.AddRange(providerLegals); var template = _licenseTemplateService.FirstOrDefault(i => i.ID == providerLicense.LicenseTemplateID.Value); var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: providerLicense.ID); _licenseContentBuilder.InsertAgreementDetails(licenseDocument, agreement.ID, linkToSchema, urlToDataLinker); var pdfBytes = new HtmlToPdfConverter().GeneratePdf(licenseDocument.OuterXml); foreach (var user in users) { var stream = new MemoryStream(pdfBytes); var attachment = new List <Attachment> { new Attachment(stream, $"{template.Name}{MailFileFormat}", MediaTypeNames.Application.Pdf) }; var email = new NewLicenseAgreementEmail { To = user.Email, From = _emailSettings.SmtpFromEmail, Name = user.Name, OrgNameConsumer = consumerOrganization.Name, OrgNameProvider = providerOrganization.Name, LinkToLicense = linkToLicense, Attachments = attachment, SchemaName = dataSchema.Name }; Send(email); } }
public void LicenseAgreementCreatedJob(int providderLicenseId, int agreementId, string linkToLicense, string linkToSchema, string urlToDataLinker, string toEmail, string toName, string consumerOrg, string providerOrg, string schemaName) { var providerLicense = _licenseService.FirstOrDefault(i => i.ID == providderLicenseId); var template = _licenseTemplateService.FirstOrDefault(i => i.ID == providerLicense.LicenseTemplateID.Value); var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: providerLicense.ID); _licenseContentBuilder.InsertAgreementDetails(licenseDocument, agreementId, linkToSchema, urlToDataLinker); var pdfBytes = new HtmlToPdfConverter().GeneratePdf(licenseDocument.OuterXml); var stream = new MemoryStream(pdfBytes); var attachment = new List <Attachment> { new Attachment(stream, $"{template.Name}{MailFileFormat}", MediaTypeNames.Application.Pdf) }; var email = new NewLicenseAgreementEmail { To = toEmail, From = _emailSettings.SmtpFromEmail, Name = toName, OrgNameConsumer = consumerOrg, OrgNameProvider = providerOrg, LinkToLicense = linkToLicense, Attachments = attachment, SchemaName = schemaName }; Send(email); }