Skip to content

Commit 7de86d9

Browse files
committed
Adding changes so we also send an email to the solver.
1 parent 3c16267 commit 7de86d9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

eFormAPI/Plugins/Workflow.Pn/Workflow.Pn/Services/WorkflowCasesService/WorkflowCasesService.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public async Task<OperationResult> UpdateWorkflowCase(WorkflowCasesUpdateModel m
396396
var createdBySite = await sdkDbContext.Sites.SingleOrDefaultAsync(x => x.Id == theCase.SiteId);
397397
if (!string.IsNullOrEmpty(workflowCase.SolvedBy))
398398
{
399-
await GenerateReportAndSendEmail(createdBySite.LanguageId, createdBySite.Name.Replace(" ", ""), workflowCase, "");
399+
await GenerateReportAndSendEmail(createdBySite.LanguageId, createdBySite.Name.Replace(" ", ""), workflowCase, workflowCase.SolvedBy);
400400
}
401401

402402
if (workflowCase.DeployedMicrotingUid != null)
@@ -867,7 +867,7 @@ private async Task SendFileAsync(
867867
string fromEmail,
868868
string fromName,
869869
string subject,
870-
string to,
870+
List<string> to,
871871
string fileName,
872872
string text = null, string html = null)
873873
{
@@ -877,8 +877,10 @@ private async Task SendFileAsync(
877877
_baseDbContext.ConfigurationValues.Single(x => x.Id == "EmailSettings:SendGridKey");
878878
var client = new SendGridClient(sendGridKey.Value);
879879
var fromEmailAddress = new EmailAddress(fromEmail.Replace(" ", ""), fromName);
880-
var toEmail = new EmailAddress(to.Replace(" ", ""));
881-
var msg = MailHelper.CreateSingleEmail(fromEmailAddress, toEmail, subject, text, html);
880+
// var toEmail = new EmailAddress(to.Replace(" ", ""));
881+
var msg = MailHelper.CreateSingleEmailToMultipleRecipients(fromEmailAddress,
882+
to.Select(x => new EmailAddress(x.Replace(" ", ""))).ToList(), subject, text, html, false);
883+
// var msg = MailHelper.CreateSingleEmail(fromEmailAddress, toEmail, subject, text, html);
882884
var bytes = await File.ReadAllBytesAsync(fileName);
883885
var file = Convert.ToBase64String(bytes);
884886
msg.AddAttachment(Path.GetFileName(fileName), file);
@@ -901,10 +903,17 @@ private async Task SendFileAsync(
901903

902904
public async Task GenerateReportAndSendEmail(int languageId, string userName, WorkflowCase workflowCase, string solvedBy)
903905
{
906+
var emailRecipients = new List<string>();
904907
var emailRecipient = await _baseDbContext.EmailRecipients.SingleOrDefaultAsync(x => x.Name.Replace(" ", "") ==
905908
userName
906909
.Replace("Mobil", "")
907910
.Replace("Tablet", ""));
911+
emailRecipients.Add(emailRecipient.Email);
912+
var solvedByemailRecipient = await _baseDbContext.EmailRecipients.SingleOrDefaultAsync(x => x.Name == solvedBy.Replace(" ", ""));
913+
if (solvedByemailRecipient != null)
914+
{
915+
emailRecipients.Add(solvedByemailRecipient.Email);
916+
}
908917
var _workflowReportHelper =
909918
new WorkflowReportHelper(await coreHelper.GetCore(), workflowPnDbContext);
910919
var filePath = await _workflowReportHelper.GenerateReportAnd(languageId, workflowCase, "pdf");
@@ -938,7 +947,7 @@ await SendFileAsync(
938947
939948
userName,
940949
$"Opfølgning: {workflowCase.IncidentType}; {workflowCase.IncidentPlace}; {workflowCase.CreatedAt:dd-MM-yyyy}",
941-
emailRecipient?.Email,
950+
emailRecipients,
942951
filePath,
943952
null,
944953
html);

0 commit comments

Comments
 (0)