Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. namespace EventHandlers.Email
  2. {
  3.     public class EmailHandler : IEventHandler<ApplicationSubmitted>, IEventHandler<ApplicationSaved>,
  4.         IEventHandler<PasswordResetRequested>, IEventHandler<CustomerCreated>
  5.     {
  6.         private IReadStore _readStore { get; set; }
  7.         private ISharedApiService _sharedApiService { get; set; }
  8.         private IEmailService _emailService { get; set; }
  9.        
  10.         public EmailHandler(IReadStore readStore, ISharedApiService sharedApiService, IEmailService emailService)
  11.         {
  12.             _readStore = readStore;
  13.             _sharedApiService = sharedApiService;
  14.             _emailService = emailService;
  15.         }
  16.  
  17.         public async Task HandleEventAsync(ApplicationSaved @event)
  18.         {
  19.             var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
  20.             var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
  21.             ApplicationSavedEmail applicationEmail = new ApplicationSavedEmail(dealership, @event.Quote, @event.ApplicationId);
  22.             await _emailService.SendEmail(recipientAddress, applicationEmail);
  23.         }
  24.        
  25.         public async Task HandleEventAsync(ApplicationSubmitted @event)
  26.         {
  27.             var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
  28.             var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
  29.             ApplicationConfirmationEmail applicationEmail = new ApplicationConfirmationEmail(dealership, @event.Quote, @event.ApplicationId);
  30.             await _emailService.SendEmail(recipientAddress, applicationEmail);
  31.         }
  32.  
  33.         public async Task HandleEventAsync(PasswordResetRequested @event)
  34.         {
  35.             var recipientAddress = (await _readStore.ById<AuthenticationReadModel>(@event.CustomerId)).Email;
  36.             var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
  37.             PasswordResetEmail email = new PasswordResetEmail(dealership, @event.ResetToken);
  38.             await _emailService.SendEmail(recipientAddress, email);
  39.         }
  40.  
  41.         public async Task HandleEventAsync(CustomerCreated @event)
  42.         {
  43.             var dealership = await _sharedApiService.GetDealershipInfo(@event.DealershipId);
  44.             RegisterEmail registerEmail = new RegisterEmail(dealership);
  45.             await _emailService.SendEmail(@event.Email, registerEmail);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement