initial commit from an older template
This commit is contained in:
56
Services/Notification/NotificationService.cs
Executable file
56
Services/Notification/NotificationService.cs
Executable file
@@ -0,0 +1,56 @@
|
||||
using System.Net.Mail;
|
||||
using GamificationService.Models.Database;
|
||||
using GamificationService.Utils;
|
||||
using GamificationService.Utils.Factory;
|
||||
|
||||
namespace GamificationService.Services.NotificationService;
|
||||
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
#region Services
|
||||
|
||||
private readonly EmailClient _emailClient;
|
||||
private readonly ILogger<NotificationService> _logger;
|
||||
private readonly PushNotificationsClient _pushNotificationsClient;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public NotificationService(EmailClient emailClient, PushNotificationsClient pushNotificationsClient, ILogger<NotificationService> logger)
|
||||
{
|
||||
_emailClient = emailClient;
|
||||
_pushNotificationsClient = pushNotificationsClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public async Task SendMailNotificationAsync(ApplicationUser user, Notification notification)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _emailClient.SendEmail(((MailNotification)notification).ConvertToMailMessage(), user.Email);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e,e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Refactor, add reg.ru notifications
|
||||
public async Task SendPushNotificationAsync(ApplicationUser user, Notification notification)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _emailClient.SendEmail(((MailNotification)notification).ConvertToMailMessage(), user.Email);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e,e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user