Skip to content

Commit

Permalink
Merge pull request #2558 from Christopher-Tihor/DEVOPS-32
Browse files Browse the repository at this point in the history
DEVOPS-32: Added new email templates and updated code to include them.
  • Loading branch information
GeorgeWalker authored Jan 10, 2025
2 parents d786be2 + f289387 commit 24905a8
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 33 deletions.
16 changes: 16 additions & 0 deletions ess/src/API/EMBC.ESS/EMBC.ESS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@
<None Remove="Engines\Supporting\SupportGeneration\ReferralPrinting\Views\Transportation\TransportationSupplierPartial.hbs" />
<None Remove="Managers\Events\Notifications\Templates\AnonymousNewTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\ETransferConfirmationTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\Images\emcr-logo.png" />
<None Remove="Managers\Events\Notifications\Templates\InviteTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\NewTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\RegisterNewTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\ResponderAnonymousNewTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\ResponderNewTemplate.hbs" />
<None Remove="Managers\Events\Notifications\Templates\ResponderRegisterNewTemplate.hbs" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -196,9 +200,21 @@
<EmbeddedResource Include="Engines\Supporting\SupportGeneration\ReferralPrinting\Views\Transportation\TransportationDeliverySummaryPartial.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\AnonymousNewTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\ETransferConfirmationTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\Images\emcr-logo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Managers\Events\Notifications\Templates\InviteTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\NewTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\RegisterNewTemplate.hbs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Managers\Events\Notifications\Templates\Images\attention-logo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Managers\Events\Notifications\Templates\ResponderAnonymousNewTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\ResponderNewTemplate.hbs" />
<EmbeddedResource Include="Managers\Events\Notifications\Templates\ResponderRegisterNewTemplate.hbs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ private async System.Threading.Tasks.Task SendEmailConfirmation(ETransferDetails
}
var totalAmount = clothingAmount + incidentalsAmount + groceryAmount + restaurantAmount + shelterAllowanceAmount;
var endDate = supports.Count() > 0 ? supports.First().To.ToPST() : DateTime.UtcNow.AddDays(3).ToPST();
string logoImage = this.ConvertImageToBase64(emcrLogoImageFileName);

await SendEmailNotification(
SubmissionTemplateType.ETransferConfirmation,
Expand All @@ -498,6 +499,7 @@ await SendEmailNotification(
KeyValuePair.Create("notificationEmail", eTransferDetails.ETransferEmail),
KeyValuePair.Create("endDate", endDate.ToString("MMMM d, yyyy")),
KeyValuePair.Create("endTime", endDate.ToString("h:mm tt")),
KeyValuePair.Create("emcrLogoImage", logoImage)
]);
}
}
76 changes: 70 additions & 6 deletions ess/src/API/EMBC.ESS/Managers/Events/EventsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Anywhere.ArcGIS.Operation;
using AutoMapper;
using EMBC.ESS.Engines.Search;
using EMBC.ESS.Engines.Supporting;
Expand All @@ -27,6 +29,8 @@
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using static System.Net.Mime.MediaTypeNames;
using Location = EMBC.ESS.Utilities.Spatial.Location;

namespace EMBC.ESS.Managers.Events;

Expand Down Expand Up @@ -57,6 +61,9 @@ public partial class EventsManager(
private readonly EvacuationFileLoader evacuationFileLoader = new(mapper, teamRepository, taskRepository, supplierRepository, supportRepository, evacueesRepository, paymentRepository);
private static TeamMemberStatus[] activeOnlyStatus = [TeamMemberStatus.Active];

private const string attentionImageFileName = $"Managers/Events/Notifications/Templates/Images/attention-logo.png";
private const string emcrLogoImageFileName = $"Managers/Events/Notifications/Templates/Images/emcr-logo.png";

public async Task<string> Handle(SubmitAnonymousEvacuationFileCommand cmd)
{
var file = mapper.Map<Resources.Evacuations.EvacuationFile>(cmd.File);
Expand All @@ -66,14 +73,20 @@ public async Task<string> Handle(SubmitAnonymousEvacuationFileCommand cmd)
file.NeedsAssessment.HouseholdMembers.Single(m => m.IsPrimaryRegistrant).LinkedRegistrantId = file.PrimaryRegistrantId;

var caseId = (await evacuationRepository.Manage(new SubmitEvacuationFileNeedsAssessment { EvacuationFile = file })).Id;
string attentionImage = this.ConvertImageToBase64(attentionImageFileName);
string logoImage = this.ConvertImageToBase64(emcrLogoImageFileName);

if (!string.IsNullOrEmpty(evacuee.Email))
{
await SendEmailNotification(
SubmissionTemplateType.NewAnonymousEvacuationFileSubmission,
email: evacuee.Email,
name: $"{evacuee.LastName}, {evacuee.FirstName}",
tokens: new[] { KeyValuePair.Create("fileNumber", caseId) });
tokens: new[] {
KeyValuePair.Create("fileNumber", caseId),
KeyValuePair.Create("attentionImage", attentionImage),
KeyValuePair.Create("emcrLogoImage", logoImage)
});
}

return caseId;
Expand All @@ -89,16 +102,33 @@ public async Task<string> Handle(SubmitEvacuationFileCommand cmd)
file.PrimaryRegistrantId = evacuee.Id;

var fileId = (await evacuationRepository.Manage(new SubmitEvacuationFileNeedsAssessment { EvacuationFile = file })).Id;
string attentionImage = this.ConvertImageToBase64(attentionImageFileName);
string logoImage = this.ConvertImageToBase64(emcrLogoImageFileName);

var shouldEmailNotification = string.IsNullOrEmpty(file.Id) && !string.IsNullOrEmpty(evacuee.Email) && string.IsNullOrEmpty(file.ManualFileId);
if (shouldEmailNotification)
{
/* DEVOPS-32: Set the email template to use based on where the request came from. */
SubmissionTemplateType templateType;
if (cmd.IsFromResponder)
{
templateType = SubmissionTemplateType.NewResponderEvacuationFileSubmission;
}
else
{
templateType = SubmissionTemplateType.NewEvacuationFileSubmission;
}

//notify registrant of the new file and has email
await SendEmailNotification(
SubmissionTemplateType.NewEvacuationFileSubmission,
templateType,
email: evacuee.Email,
name: $"{evacuee.LastName}, {evacuee.FirstName}",
tokens: new[] { KeyValuePair.Create("fileNumber", fileId) });
tokens: new[] {
KeyValuePair.Create("fileNumber", fileId),
KeyValuePair.Create("attentionImage", attentionImage),
KeyValuePair.Create("emcrLogoImage", logoImage)
});
}

return fileId;
Expand Down Expand Up @@ -138,15 +168,31 @@ public async Task<string> Handle(SaveRegistrantCommand cmd)
}

var result = await evacueesRepository.Manage(new SaveEvacuee { Evacuee = evacuee });
string logoImage = this.ConvertImageToBase64(emcrLogoImageFileName);
string attentionImage = this.ConvertImageToBase64(attentionImageFileName);

var newEvacuee = string.IsNullOrEmpty(evacuee.Id);
if (newEvacuee && !string.IsNullOrEmpty(evacuee.Email))
{
/* DEVOPS-32: Set template based on where the request came from. */
SubmissionTemplateType templateType;
if (cmd.IsFromResponder)
{
templateType = SubmissionTemplateType.NewResponderAnonymousEvacuationFileSubmission;
}
else
{
templateType = SubmissionTemplateType.NewProfileRegistration;
}

await SendEmailNotification(
SubmissionTemplateType.NewProfileRegistration,
templateType,
email: evacuee.Email,
name: $"{evacuee.LastName}, {evacuee.FirstName}",
tokens: Array.Empty<KeyValuePair<string, string>>());
tokens: new[] {
KeyValuePair.Create("attentionImage", attentionImage),
KeyValuePair.Create("emcrLogoImage", logoImage)
});
}

return result.EvacueeId;
Expand Down Expand Up @@ -438,14 +484,17 @@ public async Task<string> Handle(InviteRegistrantCommand cmd)
var invite = (await invitationRepository.Query(new EmailInvitationQuery { InviteId = inviteId })).Items.Single();
var dp = dataProtectionProvider.CreateProtector(nameof(InviteRegistrantCommand)).ToTimeLimitedDataProtector();
var encryptedInviteId = dp.Protect(inviteId, invite.ExpiryDate);
string logoImage = this.ConvertImageToBase64(emcrLogoImageFileName);

await SendEmailNotification(
SubmissionTemplateType.InviteProfile,
email: cmd.Email,
name: $"{evacuee.LastName}, {evacuee.FirstName}",
tokens: new[]
{
KeyValuePair.Create("inviteExpiryDate", invite.ExpiryDate.ToShortDateString()),
KeyValuePair.Create("inviteUrl", $"{configuration.GetValue<string>("REGISTRANTS_PORTAL_BASE_URL")}/verified-registration?inviteId={WebUtility.UrlEncode(encryptedInviteId)}")
KeyValuePair.Create("inviteUrl", $"{configuration.GetValue<string>("REGISTRANTS_PORTAL_BASE_URL")}/verified-registration?inviteId={WebUtility.UrlEncode(encryptedInviteId)}"),
KeyValuePair.Create("emcrLogoImage", logoImage)
});

return inviteId;
Expand Down Expand Up @@ -516,4 +565,19 @@ await userRepository.RecordAccessAudit(new AccessAuditEntry
RegistrantId = cmd.RegistrantId
});
}

private string ConvertImageToBase64(string imageFileName)
{
string base64Image = string.Empty;
try
{
byte[] imageArray = System.IO.File.ReadAllBytes(imageFileName);
base64Image = Convert.ToBase64String(imageArray);
}
catch (Exception ex)
{
string message = ex.Message;
}
return base64Image;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public class EmailTemplateProvider : ITemplateProvider
public async Task<Template> Get(SubmissionTemplateType template) =>
template switch
{
SubmissionTemplateType.NewAnonymousEvacuationFileSubmission => await GetAnonymousnewTemplate(),
SubmissionTemplateType.NewAnonymousEvacuationFileSubmission => await GetAnonymousNewTemplate(),
SubmissionTemplateType.NewEvacuationFileSubmission => await GetNewTemplate(),
SubmissionTemplateType.NewProfileRegistration => await GetRegisterNewTemplate(),
SubmissionTemplateType.InviteProfile => await GetInviteTemplate(),
SubmissionTemplateType.ETransferConfirmation => await GetETransferConfirmationTemplate(),
/* DEVOPS-32: New Templates */
SubmissionTemplateType.NewResponderAnonymousEvacuationFileSubmission => await GetResponderAnonymousNewTemplate(),
SubmissionTemplateType.NewResponderEvacuationFileSubmission => await GetResponderNewTemplate(),
SubmissionTemplateType.NewResponderProfileRegistration => await GetResponderRegisterNewTemplate(),

_ => throw new NotImplementedException($"No template found for {template}")
};
Expand All @@ -39,7 +43,7 @@ private async Task<EmailTemplate> GetNewTemplate()
return new EmailTemplate { Subject = emailSubject, Content = emailBody };
}

private async Task<EmailTemplate> GetAnonymousnewTemplate()
private async Task<EmailTemplate> GetAnonymousNewTemplate()
{
var emailSubject = "Registration completed successfully";
var emailBody = await LoadTemplate("AnonymousNewTemplate");
Expand All @@ -63,6 +67,27 @@ private async Task<EmailTemplate> GetInviteTemplate()
};
}

private async Task<EmailTemplate> GetResponderRegisterNewTemplate()
{
var emailSubject = "ERA User Profile Successfully Created";
var emailBody = await LoadTemplate("ResponderRegisterNewTemplate");
return new EmailTemplate { Subject = emailSubject, Content = emailBody };
}

private async Task<EmailTemplate> GetResponderNewTemplate()
{
var emailSubject = "ESS Self-Registration Completed Successfully";
var emailBody = await LoadTemplate("ResponderNewTemplate");
return new EmailTemplate { Subject = emailSubject, Content = emailBody };
}

private async Task<EmailTemplate> GetResponderAnonymousNewTemplate()
{
var emailSubject = "ERA User Profile Successfully Created";
var emailBody = await LoadTemplate("ResponderAnonymousNewTemplate");
return new EmailTemplate { Subject = emailSubject, Content = emailBody };
}

private static async Task<string> LoadTemplate(string name)
{
var assembly = Assembly.GetExecutingAssembly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public enum SubmissionTemplateType
NewAnonymousEvacuationFileSubmission,
NewProfileRegistration,
InviteProfile,
ETransferConfirmation
ETransferConfirmation,
NewResponderAnonymousEvacuationFileSubmission,
NewResponderEvacuationFileSubmission,
NewResponderProfileRegistration
}

public abstract class Template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<p style='font-size: 18pt;color:#234075;font-weight: bold;'>Submission Successful</p>
<p style='font-size: 13pt;color:#00a6ed;font-weight: bold;'>Your Emergency Support Services (ESS) File Number is: {{fileNumber}}</p>
<p><strong>Thank you for submitting your online self-registration. Please keep a record of your Emergency Support Services File Number as you will need this when you connect with an ESS Responder.</strong></p>
<div style="background-color:yellow">
<p style='font-size: 16pt;color:#00a6ed;font-weight: bold;'><img src="Images/attention-logo.png" alt="!">Next Steps if you are under EVACUATION ORDER:</p>
<div style="background-color:cornsilk">
<p style='font-size: 16pt;color:#00a6ed;font-weight: bold;'><img src="data:image/jpeg;charset=utf-8;base64,{{attentionImage}}" alt="!">Next Steps if you are under EVACUATION ORDER:</p>
<ul>
<li>
If you require emergency supports, review your evacuation order and proceed to your nearest Reception Centre. A list of open Reception Centres can be found at <a href="https://www.emergencyinfobc.gov.bc.ca/" style="color:#00a6ed;text-decoration:underline;">Emergency Info BC</a>.
Expand All @@ -32,12 +32,12 @@
If you <strong>DO NOT</strong> require emergency services at this time, no further action is required. If your Alert turns into an ORDER – please see the above actions.
</li>
</ul>
<p>If you need help with your Evacuee Registration and Assistance (ERA) profile or Service BC authentication, please contact our toll-free support line at 1-800-387-4258. Our support team is available: Monday to Friday: 7:30 AM to 5:00 PM (excluding statutory holidays).</p>
<br />
</td>
</tr>
<tr>
<td style="padding:30px;text-align:center;font-size:12px;background-color:#234075;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="https://ess.gov.bc.ca/img/gov_bc_logo.svg" width="150" height="41" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
<td style="padding:30px;text-align:center;font-size:12px;background-color:white;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="data:image/jpeg;charset=utf-8;base64,{{emcrLogoImage}}" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{/if}}
<p>
<p style='font-size: 13pt;font-weight: bold;'>Total Amount: ${{totalAmount}}</p>
<div style="background-color:yellow">
<div style="background-color:cornsilk">
<p style='font-size: 13pt;color:#00a6ed;font-weight: bold;'>Next Steps:</p>
<ul>
<li>
Expand Down Expand Up @@ -60,11 +60,12 @@
<br /><i style="color: #808080">(select the 'Already have an account? Log in' button)</i>
</strong>
</p>
<p>If you need help with your Evacuee Registration and Assistance (ERA) profile or Service BC authentication, please contact our toll-free support line at 1-800-387-4258. Our support team is available: Monday to Friday: 7:30 AM to 5:00 PM (excluding statutory holidays).</p>
</td>
</tr>
<tr>
<td style="padding:30px;text-align:center;font-size:12px;background-color:#234075;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="https://ess.gov.bc.ca/img/gov_bc_logo.svg" width="150" height="41" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
<td style="padding:30px;text-align:center;font-size:12px;background-color:white;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="data:image/jpeg;charset=utf-8;base64,{{emcrLogoImage}}" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
</td>
</tr>
</tbody>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
Sincerely,<br />
<strong>Ministry of Emergency Management and Climate Readiness</strong>
</p>
<p>If you need help with your Evacuee Registration and Assistance (ERA) profile or Service BC authentication, please contact our toll-free support line at 1-800-387-4258. Our support team is available: Monday to Friday: 7:30 AM to 5:00 PM (excluding statutory holidays).</p>
</td>
</tr>
<tr>
<td style="padding:30px;text-align:center;font-size:12px;background-color:#234075;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="https://ess.gov.bc.ca/img/gov_bc_logo.svg" width="150" height="41" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
<td style="padding:30px;text-align:center;font-size:12px;background-color:white;color:#cccccc;">
<p style="margin:0 0 8px 0;"><a style="text-decoration:none;"><img src="data:image/jpeg;charset=utf-8;base64,{{emcrLogoImage}}" alt="Government of British Columbia" style="display:inline-block;color:#cccccc;"></a></p>
</td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit 24905a8

Please sign in to comment.