public async Task Handle(TodoListItemCompletedStateChanged notification, CancellationToken cancellationToken) { _logger.LogInformation($"Handling {notification.Item.Id} completed state changed. Completed = '{notification.Item.Completed}'."); var item = notification.Item; var emails = await _dapper.GetEmailsFromAccountsByListIdAsync(item.ListId.GetValueOrDefault()); var messages = new List <EmailMessage>(); if (item.Completed) { foreach (var userEmail in emails) { var account = await _account.FindAccountByEmailAsync(userEmail); var accountPlan = await _accountPlan.FindAccountPlanByAccountIdAsync(account.Id); if (accountPlan.PlanId == PlanTiers.Basic || accountPlan.PlanId == PlanTiers.Premium && account.EmailItemCompleted == true) { messages.Add( new EmailMessage() { To = userEmail, From = _config.GetSection("Emails")["Notifications"], Subject = $"You completed a item!", Body = $"{item.Name} is completed! Nice work!" }); } } _logger.LogInformation($"Sending email notification for completed item {item.Id}."); await _emailQueue.QueueEmailAsync(messages); } }
public async Task Handle(InvitationSent notification, CancellationToken cancellationToken) { _logger.LogInformation($"Handling {notification.InviteeAccountId} Invitation sent '{notification.InviteeAccountId}'."); var messages = new List <EmailMessage>(); var inviteeAccount = await _account.FindAccountByIdAsync(notification.InviteeAccountId); var inviteeAccountPlan = await _accountPlan.FindAccountPlanByAccountIdAsync(inviteeAccount.Id); if (inviteeAccountPlan.PlanId == PlanTiers.Basic || inviteeAccountPlan.PlanId == PlanTiers.Premium && inviteeAccount.EmailInvitation == true) { messages.Add( new EmailMessage() { To = inviteeAccount.Email, From = _config.GetSection("Emails")["Notifications"], Subject = $"You're invited to a list.", Body = $"You've been sent an invitation to a list! Go check it out!" }); } _logger.LogInformation($"Sending email notification for Invitation sent."); await _emailQueue.QueueEmailAsync(messages); }