NEW: Zusagen / Absagen Chart (PoC)

This commit is contained in:
2025-12-04 22:57:22 +01:00
parent ab237de4c8
commit a31292e476
6 changed files with 138 additions and 103 deletions

View File

@ -130,6 +130,24 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Controllers
return (null, null);
}
}
// GET api/<controller>/5
[HttpGet("all-respones/{id}/{moduleid}")]
[Authorize(Policy = PolicyNames.ViewModule)]
public async Task<List<Models.Response>> GetResponses(int id, int moduleid)
{
List<Models.Response> eventResponses = await _EventRegistrationService.GetEventResponses(id, moduleid);
if (eventResponses != null && IsAuthorizedEntityId(EntityNames.Module, moduleid))
{
return eventResponses;
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Get Attempt {EventRegistrationId} {ModuleId}", id, moduleid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
}
// TODO: Add Event Response Endpoints.
}

View File

@ -121,6 +121,34 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
return null;
}
}
public Task<List<Event>> GetEventsAsync(int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_EventRepository.GetEvents(ModuleId).ToList());
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Events Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<Event> UpdateEventAsync(Event UpdatedEvent)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, UpdatedEvent.ModuleId, PermissionNames.Edit))
{
UpdatedEvent = _EventRepository.UpdateEvent(UpdatedEvent);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Event Updated {NewEvent}", UpdatedEvent);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Update Attempt {NewEvent}", UpdatedEvent);
UpdatedEvent = null;
}
return Task.FromResult(UpdatedEvent);
}
public Task<(Event, Response)> GetEventDetails(int EventId, int ModuleId)
{
@ -148,86 +176,14 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Response Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<List<Response>> GetRecommendedEventResponses(int EventId, int MouleId)
{
throw new System.NotImplementedException();
}
public Task<List<Event>> GetEventsAsync(int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_EventRepository.GetEvents(ModuleId).ToList());
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Events Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<Event> UpdateEventAsync(Event NewEvent)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, NewEvent.ModuleId, PermissionNames.Edit))
{
NewEvent = _EventRepository.UpdateEvent(NewEvent);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Event Updated {NewEvent}", NewEvent);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Update Attempt {NewEvent}", NewEvent);
NewEvent = null;
}
return Task.FromResult(NewEvent);
}
// TODO: Implement the methods for EventResponses
/*
public Task<Models.Event> GetEventRegistrationAsync(int EventRegistrationId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_EventRegistrationRepository.GetEventRegistration(EventRegistrationId));
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Get Attempt {EventRegistrationId} {ModuleId}", EventRegistrationId, ModuleId);
return null;
}
}
public Task<Models.Event> AddEventRegistrationAsync(Models.Event EventRegistration)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, EventRegistration.ModuleId, PermissionNames.Edit))
{
EventRegistration = _EventRegistrationRepository.AddEventRegistration(EventRegistration);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {EventRegistration}", EventRegistration);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Add Attempt {EventRegistration}", EventRegistration);
EventRegistration = null;
}
return Task.FromResult(EventRegistration);
}
public Task<Models.Event> UpdateEventRegistrationAsync(Models.Event EventRegistration)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, EventRegistration.ModuleId, PermissionNames.Edit))
{
EventRegistration = _EventRegistrationRepository.UpdateEventRegistration(EventRegistration);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "EventRegistration Updated {EventRegistration}", EventRegistration);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Update Attempt {EventRegistration}", EventRegistration);
EventRegistration = null;
}
return Task.FromResult(EventRegistration);
}
}*/
private void SendEventResponseNotification(string subject, string body)
{
User user = _UserRepository.GetUser(_accessor.HttpContext.User.UserId());

View File

@ -2,4 +2,25 @@
var SZUAbsolventenverein = SZUAbsolventenverein || {};
SZUAbsolventenverein.EventRegistration = {
createChart: async function (divid, type, labels, datasets, options) {
var container = document.getElementById(divid);
if (container.hasChildNodes()) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
}
var canvas = document.createElement('canvas');
canvas.id = divid + '-canvas';
container.appendChild(canvas);
var ctx = canvas.getContext('2d');
var chart = new Chart(ctx, {
type: type,
data: {
labels: labels,
datasets: datasets
},
options: options
});
}
};