-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSendWelcomingEmail.cs
More file actions
27 lines (23 loc) · 1.09 KB
/
SendWelcomingEmail.cs
File metadata and controls
27 lines (23 loc) · 1.09 KB
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
using System.Threading;
using System.Threading.Tasks;
using EntityFrameworkCore.Triggered;
using StudentManager.Services;
namespace StudentManager.Triggers.StudentCourses
{
public class SendWelcomingEmail : IAfterSaveAsyncTrigger<StudentCourse>
{
readonly ApplicationDbContext _applicationContext;
readonly EmailService _emailService;
public SendWelcomingEmail(ApplicationDbContext applicationContext, EmailService emailService)
{
_applicationContext = applicationContext;
_emailService = emailService;
}
public async Task AfterSaveAsync(ITriggerContext<StudentCourse> context, CancellationToken cancellationToken)
{
var student = await _applicationContext.Students.FindAsync(new object[] { context.Entity.StudentId }, cancellationToken);
var course = await _applicationContext.Courses.FindAsync(new object[] { context.Entity.CourseId }, cancellationToken);
_emailService.SendEmail(student, $"Welcoming {student.DisplayName} to the course: {course.DisplayName}");
}
}
}