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.BlackBoard.Repository;
|
|
|
|
namespace SZUAbsolventenverein.Module.BlackBoard.Services
|
|
{
|
|
public class ServerBlackBoardService : IBlackBoardService
|
|
{
|
|
private readonly IBlackBoardRepository _BlackBoardRepository;
|
|
private readonly IUserPermissions _userPermissions;
|
|
private readonly ILogManager _logger;
|
|
private readonly IHttpContextAccessor _accessor;
|
|
private readonly Alias _alias;
|
|
|
|
public ServerBlackBoardService(IBlackBoardRepository BlackBoardRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
|
{
|
|
_BlackBoardRepository = BlackBoardRepository;
|
|
_userPermissions = userPermissions;
|
|
_logger = logger;
|
|
_accessor = accessor;
|
|
_alias = tenantManager.GetAlias();
|
|
}
|
|
|
|
public Task<List<Models.BlackBoard>> GetBlackBoardsAsync(int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
{
|
|
return Task.FromResult(_BlackBoardRepository.GetBlackBoards(ModuleId).ToList());
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized BlackBoard Get Attempt {ModuleId}", ModuleId);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public Task<Models.BlackBoard> GetBlackBoardAsync(int BlackBoardId, int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
{
|
|
return Task.FromResult(_BlackBoardRepository.GetBlackBoard(BlackBoardId));
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized BlackBoard Get Attempt {BlackBoardId} {ModuleId}", BlackBoardId, ModuleId);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public Task<Models.BlackBoard> AddBlackBoardAsync(Models.BlackBoard BlackBoard)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, BlackBoard.ModuleId, PermissionNames.Edit))
|
|
{
|
|
BlackBoard = _BlackBoardRepository.AddBlackBoard(BlackBoard);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "BlackBoard Added {BlackBoard}", BlackBoard);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized BlackBoard Add Attempt {BlackBoard}", BlackBoard);
|
|
BlackBoard = null;
|
|
}
|
|
return Task.FromResult(BlackBoard);
|
|
}
|
|
|
|
public Task<Models.BlackBoard> UpdateBlackBoardAsync(Models.BlackBoard BlackBoard)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, BlackBoard.ModuleId, PermissionNames.Edit))
|
|
{
|
|
BlackBoard = _BlackBoardRepository.UpdateBlackBoard(BlackBoard);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "BlackBoard Updated {BlackBoard}", BlackBoard);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized BlackBoard Update Attempt {BlackBoard}", BlackBoard);
|
|
BlackBoard = null;
|
|
}
|
|
return Task.FromResult(BlackBoard);
|
|
}
|
|
|
|
public Task DeleteBlackBoardAsync(int BlackBoardId, int ModuleId)
|
|
{
|
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
|
{
|
|
_BlackBoardRepository.DeleteBlackBoard(BlackBoardId);
|
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "BlackBoard Deleted {BlackBoardId}", BlackBoardId);
|
|
}
|
|
else
|
|
{
|
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized BlackBoard Delete Attempt {BlackBoardId} {ModuleId}", BlackBoardId, ModuleId);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|