private async Task NotifyAd(Shared.Functional.AdModel ad, string eventType, EmailTemplateEnum emailTemplate, NotificationTypeEnum notificationType, string callbackUrl) { _logger.LogInformation($"notify user {ad.OwnerId} for ad {ad.Id}"); await _eventTrackingService.Create(ad.OwnerId, "Ad", eventType); var notification = new Notification { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, CssClass = "advalidate", ImageUrl = "alert-advalidate", MessageTitle = eventType, NotificationIcon = "alert-advalidate", NotificationType = notificationType.GetName(), NotificationUrl = callbackUrl, UserId = ad.OwnerId, DisplayMax = 1, IsDisplayOnlyOnce = true }; await _notificationService.Create(notification); await SendEmailTemplate(ad, emailTemplate, callbackUrl); }
private async Task SendEmailTemplate(Shared.Functional.AdModel ad, EmailTemplateEnum emailType, string callbackUrl) { _logger.LogInformation($"send email {emailType} to user {ad.OwnerId}"); var frontWebSite = _configuration["Service:FrontOffice:Url"]; var logoUrl = $"{frontWebSite.TrimEnd('/')}/assets/img/logo_full.png"; var unSubscribeUrl = $"{frontWebSite.TrimEnd('/')}/Account/UnSubscribe"; var parameters = new Dictionary <string, string>() { { "title", ad.Title }, { "frontWebSite", frontWebSite }, { "logoUrl", logoUrl }, { "unSubscribeUrl", unSubscribeUrl }, { "callbackUrl", callbackUrl } }; if (emailType == EmailTemplateEnum.AdEndPublished) { parameters.Add("EndPublishingDate", ad.EndDisplayTime.Value.ToLongDateString()); parameters.Add("ViewCount", ad.ViewCount.ToString()); } var message = GenerateHtmlTemplate(_serviceProvider, _env.WebRootPath, emailType, parameters); var user = await _userManager.FindByIdAsync(ad.OwnerId); await _emailSender.SendEmailAsync(user.Email, ad.Title, message); }