102 lines
4.8 KiB
C#
102 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Oqtane.Enums;
|
|
using Oqtane.Infrastructure;
|
|
using Oqtane.Models;
|
|
using Oqtane.Security;
|
|
using Oqtane.Shared;
|
|
using SZUAbsolventenverein.Module.EventRegistration.Repository;
|
|
|
|
namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|
{
|
|
public class ServerEventRegistrationService : IEventRegistrationService
|
|
{
|
|
private readonly IEventRegistrationRepository _EventRegistrationRepository;
|
|
private readonly IUserPermissions _userPermissions;
|
|
private readonly ILogManager _logger;
|
|
private readonly IHttpContextAccessor _accessor;
|
|
private readonly Alias _alias;
|
|
|
|
public ServerEventRegistrationService(IEventRegistrationRepository EventRegistrationRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
|
{
|
|
_EventRegistrationRepository = EventRegistrationRepository;
|
|
_userPermissions = userPermissions;
|
|
_logger = logger;
|
|
_accessor = accessor;
|
|
_alias = tenantManager.GetAlias();
|
|
}
|
|
|
|
public Task<List<Models.Event>> GetEventRegistrationsAsync(int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
{
|
|
return Task.FromResult(_EventRegistrationRepository.GetEventRegistrations(ModuleId).ToList());
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Get Attempt {ModuleId}", ModuleId);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public Task DeleteEventRegistrationAsync(int EventRegistrationId, int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
|
{
|
|
_EventRegistrationRepository.DeleteEventRegistration(EventRegistrationId);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "EventRegistration Deleted {EventRegistrationId}", EventRegistrationId);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Delete Attempt {EventRegistrationId} {ModuleId}", EventRegistrationId, ModuleId);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|