102 lines
4.4 KiB
C#
102 lines
4.4 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.HallOfFame.Repository;
|
|
|
|
namespace SZUAbsolventenverein.Module.HallOfFame.Services
|
|
{
|
|
public class ServerHallOfFameService : IHallOfFameService
|
|
{
|
|
private readonly IHallOfFameRepository _HallOfFameRepository;
|
|
private readonly IUserPermissions _userPermissions;
|
|
private readonly ILogManager _logger;
|
|
private readonly IHttpContextAccessor _accessor;
|
|
private readonly Alias _alias;
|
|
|
|
public ServerHallOfFameService(IHallOfFameRepository HallOfFameRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
|
{
|
|
_HallOfFameRepository = HallOfFameRepository;
|
|
_userPermissions = userPermissions;
|
|
_logger = logger;
|
|
_accessor = accessor;
|
|
_alias = tenantManager.GetAlias();
|
|
}
|
|
|
|
public Task<List<Models.HallOfFame>> GetHallOfFamesAsync(int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
{
|
|
return Task.FromResult(_HallOfFameRepository.GetHallOfFames(ModuleId).ToList());
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Get Attempt {ModuleId}", ModuleId);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public Task<Models.HallOfFame> GetHallOfFameAsync(int HallOfFameId, int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
{
|
|
return Task.FromResult(_HallOfFameRepository.GetHallOfFame(HallOfFameId));
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Get Attempt {HallOfFameId} {ModuleId}", HallOfFameId, ModuleId);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, HallOfFame.ModuleId, PermissionNames.Edit))
|
|
{
|
|
HallOfFame = _HallOfFameRepository.AddHallOfFame(HallOfFame);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "HallOfFame Added {HallOfFame}", HallOfFame);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Add Attempt {HallOfFame}", HallOfFame);
|
|
HallOfFame = null;
|
|
}
|
|
return Task.FromResult(HallOfFame);
|
|
}
|
|
|
|
public Task<Models.HallOfFame> UpdateHallOfFameAsync(Models.HallOfFame HallOfFame)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, HallOfFame.ModuleId, PermissionNames.Edit))
|
|
{
|
|
HallOfFame = _HallOfFameRepository.UpdateHallOfFame(HallOfFame);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "HallOfFame Updated {HallOfFame}", HallOfFame);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Update Attempt {HallOfFame}", HallOfFame);
|
|
HallOfFame = null;
|
|
}
|
|
return Task.FromResult(HallOfFame);
|
|
}
|
|
|
|
public Task DeleteHallOfFameAsync(int HallOfFameId, int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
|
{
|
|
_HallOfFameRepository.DeleteHallOfFame(HallOfFameId);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "HallOfFame Deleted {HallOfFameId}", HallOfFameId);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Delete Attempt {HallOfFameId} {ModuleId}", HallOfFameId, ModuleId);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|