Exemplo n.º 1
0
        private async Task SendEmailAsync(JumpStart jumpStart)
        {
            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Name);

            var pdfUrl = await _jumpStartPdfService.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart.DateTime, jumpStart.Posts);

            var recipients = await GetRecipients(jumpStart.Id);

            var subject =
                $"Project Blue Delta - {jumpStart.DateTime.InZone(VolkswagenCompany.TimeZoneId, "MMMM d, yyyy")}";

            foreach (var batch in recipients.Batch(SendGridService.BatchSize))
            {
                var subjects = Enumerable.Repeat(subject, batch.Count).ToList();

                var substitutions = Enumerable.Repeat(new Dictionary <string, string>
                {
                    { "{{print_url}}", pdfUrl }
                }, batch.Count).ToList();

                await _sendGridService.SendEmail(company.Id, batch, subjects, emailTemplate, emailTemplate, substitutions,
                                                 jumpStart.DateTime);

                foreach (var recipient in batch)
                {
                    recipient.Status = EmailStatus.Sent;
                }

                await _dbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        private async Task SendEmailAsync(JumpStart jumpStart)
        {
            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Name);

            var pdfUrl = await _jumpStartPdfService.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart, jumpStart.Articles, pdfUrl);

            var recipients = await GetRecipients(jumpStart.Id);

            var subject =
                $"Project Blue Delta - {jumpStart.DateTime.InZone(VolkswagenCompany.TimeZoneId, "MMMM d, yyyy")}";

            foreach (var batch in recipients.Batch(SendGridService.BatchSize))
            {
                await _sendGridService.SendEmail(company.Id, batch, subject, emailTemplate, emailTemplate, jumpStart.DateTime);

                foreach (var recipient in batch)
                {
                    recipient.Status = EmailStatus.Sent;
                }

                await _dbContext.SaveChangesAsync();
            }
        }