EventRegistrationService: Add Notifications on subscribe/unsubscribe.
Changed: EventRegistrationService.cs Co-Author: Florian Edlmayer <florian.edlmayer@edu.szu.at>
This commit is contained in:
@ -17,15 +17,19 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
{
|
||||
private readonly IEventRepository _EventRepository;
|
||||
private readonly IResponseRepository _ResponseRepository;
|
||||
private readonly INotificationRepository _NotificationRepository;
|
||||
private readonly IUserRepository _UserRepository;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public ServerEventRegistrationService(IEventRepository EventRepository, IResponseRepository ResponseRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
||||
public ServerEventRegistrationService(IEventRepository EventRepository, IResponseRepository ResponseRepository, INotificationRepository NotificationRepository, IUserRepository UserRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
||||
{
|
||||
_EventRepository = EventRepository;
|
||||
_ResponseRepository = ResponseRepository;
|
||||
_NotificationRepository = NotificationRepository;
|
||||
_UserRepository = UserRepository;
|
||||
_userPermissions = userPermissions;
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
@ -52,6 +56,12 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, Response.ModuleId, PermissionNames.View))
|
||||
{
|
||||
Response = _ResponseRepository.AddResponse(Response);
|
||||
|
||||
Event currentEvent = _EventRepository.GetEvent(Response.EventRegistrationId);
|
||||
string subject = Response.ResponseType ? $"Du bist erfolgreich für '{currentEvent.Name}' Registriert worden." : $"Du hast erfolgreich für '{currentEvent.Name}' abgesagt.";
|
||||
string body = "Hier kann man die Infos des Events hineinpacken (HTML ist erlaubt)";
|
||||
SendEventResponseNotification(subject, body);
|
||||
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {NewEvent}", Response);
|
||||
}
|
||||
else
|
||||
@ -68,6 +78,12 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, Response.ModuleId, PermissionNames.View))
|
||||
{
|
||||
Response = _ResponseRepository.UpdateResponse(Response);
|
||||
|
||||
Event currentEvent = _EventRepository.GetEvent(Response.EventRegistrationId);
|
||||
string subject = Response.ResponseType ? $"Du bist erfolgreich für '{currentEvent.Name}' Registriert worden." : $"Du hast erfolgreich für '{currentEvent.Name}' abgesagt.";
|
||||
string body = "Hier kann man die Infos des Events hineinpacken (HTML ist erlaubt)";
|
||||
SendEventResponseNotification(subject, body);
|
||||
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {NewEvent}", Response);
|
||||
}
|
||||
else
|
||||
@ -211,7 +227,11 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
private void SendEventResponseNotification(string subject, string body)
|
||||
{
|
||||
User user = _UserRepository.GetUser(_accessor.HttpContext.User.UserId());
|
||||
Notification notification = new Notification(_alias.SiteId, user, subject, body);
|
||||
_NotificationRepository.AddNotification(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user