-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBadgeAwardTemplate.cs
42 lines (34 loc) · 1.36 KB
/
BadgeAwardTemplate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using BadgeMeUp.Models;
namespace BadgeMeUp;
public class BadgeAwardTemplate
{
public static EmailQueue GetEmailQueue(string toEmail, Badge badge, User from, string comment)
{
var email = new EmailQueue
{
ToEmail = toEmail, Subject = $"You just earned a new badge - {badge.Name}!", Body = GetEmailBody(badge, from, comment)
};
return email;
}
private static string GetEmailBody(Badge badge, User from, string comment)
{
var bytes = typeof(BadgeAwardTemplate).Assembly.GetManifestResourceStream("BadgeMeUp.BadgeAwardEmail.html");
if(bytes == null)
{
//Console.WriteLine(typeof(BadgeAwardTemplate).Assembly.GetManifestResourceNames());
return string.Empty;
}
using var sr = new StreamReader(bytes);
var template = sr.ReadToEnd();
if(!string.IsNullOrWhiteSpace(comment))
{
comment = "Message from the sender: " + comment;
}
template = template.Replace("{BadgeName}", badge.Name);
template = template.Replace("{BadgeId}", badge.Id.ToString());
template = template.Replace("{FromUserName}", from.PrincipalName);
template = template.Replace("{BadgeDescription}", badge.Description);
template = template.Replace("{AwardComment}", comment);
return template;
}
}