Пример #1
0
        public async Task <IActionResult> Create(string html, CancellationToken cancellationToken = default)
        {
            var host = HttpContext.GetHost();

            if (string.IsNullOrWhiteSpace(host))
            {
                return(BadRequest());
            }

            if (await smtpConfigsRepository.Get(c => c.Active, cancellationToken) is Smtp config)
            {
                var email = NotificationModelFactory.CreateNotificationModel <IEmailNotificationModel>()
                            .SetConfiguration(config.Host, config.Port, config.Username, config.Password, (SecureSocketOptions)config.SecureSocketOption)
                            .SetAuthors("*****@*****.**", "*****@*****.**")
                            .SetRecipients("*****@*****.**")
                            .SetSubject("Testowa wiadomość")
                            .SetBody(TextFormat.Html, $"<h1>Uruchomiono generator PDF - {DateTime.UtcNow}</h1>")
                            .Encrypt(Keys.RSA.PublicKey);


                notificationService.Save(email.Serialize());
            }

            var bytes = await this.pdfService.Generate(html, host, cancellationToken);

            if (bytes is null)
            {
                return(BadRequest());
            }

            return(File(bytes, "application/pdf"));
        }
Пример #2
0
        public Task <SmtpModel> GetAsync(int id)
        {
            var dal = _smtpRepository.Get(id);

            if (dal == null)
            {
                return(Task.FromResult <SmtpModel>(null));
            }
            else
            {
                SmtpModel model = AutoMapperGenericHelper <Smtp, SmtpModel> .Convert(dal);

                return(Task.FromResult(model));
            }
        }