private async Task SendProjectCreateNotification(IProjectData model) { var message = NotificationMessageHelper.CreateProjectMessage(model); foreach (var email in _settings.LykkeStreams.ProjectCreateNotificationReceiver) { await _emailSender.SendEmailAsync(NotificationMessageHelper.EmailSender, email, message); } }
private async Task SendNotificationAsync(TierUpgradeRequestChangedEvent evt, ICommandSender commandSender) { var clientAccTask = _clientAccountClient.ClientAccountInformation.GetByIdAsync(evt.ClientId); var personalDataTask = _personalDataService.GetAsync(evt.ClientId); var pushSettingsTask = _clientAccountClient.ClientSettings.GetPushNotificationAsync(evt.ClientId); await Task.WhenAll(clientAccTask, personalDataTask, pushSettingsTask); var clientAcc = clientAccTask.Result; var personalData = personalDataTask.Result; var pushSettings = pushSettingsTask.Result; bool pushEnabled = pushSettings.Enabled && !string.IsNullOrEmpty(clientAcc.NotificationsId); Task <EmailMessage> emailTemplateTask = Task.FromResult <EmailMessage>(null); Task <EmailMessage> pushTemplateTask = Task.FromResult <EmailMessage>(null); string type = string.Empty; try { switch (evt.NewStatus) { case KycStatus.Ok: var tierInfo = await _tiersService.GetClientTierInfoAsync(evt.ClientId, clientAcc.Tier, personalData.CountryFromPOA); bool noAmountTemplate = tierInfo.CurrentTier.MaxLimit == 0; string upgradeTemplate = tierInfo.CurrentTier.Tier == AccountTier.Advanced ? "TierUpgradedToProTemplate" : "TierUpgradedTemplate"; emailTemplateTask = _templateFormatter.FormatAsync(noAmountTemplate ? "TierUpgradedNoAmountTemplate" : upgradeTemplate, clientAcc.PartnerId, "EN", new { Tier = evt.Tier.ToString(), Year = DateTime.UtcNow.Year, Amount = $"{tierInfo.CurrentTier.MaxLimit} {tierInfo.CurrentTier.Asset}", //TODO: remove when TierUpgradedTemplate will be updated (@[UpgradeText] removed) UpgradeText = string.Empty }); if (pushEnabled) { pushTemplateTask = _templateFormatter.FormatAsync(noAmountTemplate ? "PushTierUpgradedNoAmountTemplate" : "PushTierUpgradedTemplate", clientAcc.PartnerId, "EN", new { Tier = evt.Tier.ToString(), Amount = $"{tierInfo.CurrentTier.MaxLimit} {tierInfo.CurrentTier.Asset}" }); } type = NotificationType.TierUpgraded.ToString(); break; case KycStatus.NeedToFillData: var documents = await _kycDocumentsService.GetCurrentDocumentsAsync(evt.ClientId); var declinedDocuments = documents .Where(item => item.Status.Name == CheckDocumentPorcess.DeclinedState.Name) .ToArray(); if (declinedDocuments.Length > 0) { string documentsAsHtml = GetDocumentsInfo(declinedDocuments); emailTemplateTask = _templateFormatter.FormatAsync("DeclinedDocumentsTemplate", clientAcc.PartnerId, "EN", new { FullName = personalData.FullName, DocumentsAsHtml = documentsAsHtml, Year = DateTime.UtcNow.Year }); } if (pushEnabled) { pushTemplateTask = _templateFormatter.FormatAsync("PushKycNeedDocumentsTemplate", clientAcc.PartnerId, "EN", new { }); } type = NotificationType.KycNeedToFillDocuments.ToString(); break; case KycStatus.Rejected: emailTemplateTask = _templateFormatter.FormatAsync("TierUpgradeRejectedTemplate", clientAcc.PartnerId, "EN", new { FullName = personalData.FullName, Tier = evt.Tier.ToString(), Year = DateTime.UtcNow.Year }); break; } } finally { await Task.WhenAll(emailTemplateTask, pushTemplateTask); var sendEmailTask = Task.CompletedTask; if (emailTemplateTask.Result != null) { var msgData = new PlainTextData { Sender = personalData.Email, Subject = emailTemplateTask.Result.Subject, Text = emailTemplateTask.Result.HtmlBody }; sendEmailTask = _emailSender.SendEmailAsync(clientAcc.PartnerId, personalData.Email, msgData); } if (pushEnabled && pushTemplateTask.Result != null) { commandSender.SendCommand(new TextNotificationCommand { NotificationIds = new[] { clientAcc.NotificationsId }, Type = type, Message = pushTemplateTask.Result.Subject }, PushNotificationsBoundedContext.Name); } await sendEmailTask; } }