Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace EventHandlers.Email
- {
- public class EmailHandler : IEventHandler<ApplicationSubmitted>, IEventHandler<ApplicationSaved>,
- IEventHandler<PasswordResetRequested>, IEventHandler<CustomerCreated>
- {
- private IReadStore _readStore { get; set; }
- private ISharedApiService _sharedApiService { get; set; }
- private IEmailService _emailService { get; set; }
- public EmailHandler(IReadStore readStore, ISharedApiService sharedApiService, IEmailService emailService)
- {
- _readStore = readStore;
- _sharedApiService = sharedApiService;
- _emailService = emailService;
- }
- public async Task HandleEventAsync(ApplicationSaved @event)
- {
- var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
- var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
- ApplicationSavedEmail applicationEmail = new ApplicationSavedEmail(dealership, @event.Quote, @event.ApplicationId);
- await _emailService.SendEmail(recipientAddress, applicationEmail);
- }
- public async Task HandleEventAsync(ApplicationSubmitted @event)
- {
- var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
- var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
- ApplicationConfirmationEmail applicationEmail = new ApplicationConfirmationEmail(dealership, @event.Quote, @event.ApplicationId);
- await _emailService.SendEmail(recipientAddress, applicationEmail);
- }
- public async Task HandleEventAsync(PasswordResetRequested @event)
- {
- var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
- var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
- PasswordResetEmail email = new PasswordResetEmail(dealership, @event.ResetToken);
- await _emailService.SendEmail(recipientAddress, email);
- }
- public async Task HandleEventAsync(CustomerCreated @event)
- {
- var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
- RegisterEmail registerEmail = new RegisterEmail(dealership);
- await _emailService.SendEmail(@event.Email, registerEmail);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement