From 527f9aadc617b0ba94ad8dd3145f8f77b57516a7 Mon Sep 17 00:00:00 2001 From: Konstantin Hintermayer Date: Fri, 30 May 2025 09:38:09 +0200 Subject: [PATCH] EventRegistrationService: Add Notifications on subscribe/unsubscribe. Changed: EventRegistrationService.cs Co-Author: Florian Edlmayer --- Server/Services/EventRegistrationService.cs | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Server/Services/EventRegistrationService.cs b/Server/Services/EventRegistrationService.cs index 54c9934..8f1112e 100644 --- a/Server/Services/EventRegistrationService.cs +++ b/Server/Services/EventRegistrationService.cs @@ -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); + } } }