Initial commit
This commit is contained in:
101
Server/Services/PremiumAreaService.cs
Normal file
101
Server/Services/PremiumAreaService.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
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.PremiumArea.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.PremiumArea.Services
|
||||
{
|
||||
public class ServerPremiumAreaService : IPremiumAreaService
|
||||
{
|
||||
private readonly IPremiumAreaRepository _PremiumAreaRepository;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public ServerPremiumAreaService(IPremiumAreaRepository PremiumAreaRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
||||
{
|
||||
_PremiumAreaRepository = PremiumAreaRepository;
|
||||
_userPermissions = userPermissions;
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
public Task<List<Models.PremiumArea>> GetPremiumAreasAsync(int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
return Task.FromResult(_PremiumAreaRepository.GetPremiumAreas(ModuleId).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PremiumArea Get Attempt {ModuleId}", ModuleId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Models.PremiumArea> GetPremiumAreaAsync(int PremiumAreaId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
return Task.FromResult(_PremiumAreaRepository.GetPremiumArea(PremiumAreaId));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PremiumArea Get Attempt {PremiumAreaId} {ModuleId}", PremiumAreaId, ModuleId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Models.PremiumArea> AddPremiumAreaAsync(Models.PremiumArea PremiumArea)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, PremiumArea.ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
PremiumArea = _PremiumAreaRepository.AddPremiumArea(PremiumArea);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "PremiumArea Added {PremiumArea}", PremiumArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PremiumArea Add Attempt {PremiumArea}", PremiumArea);
|
||||
PremiumArea = null;
|
||||
}
|
||||
return Task.FromResult(PremiumArea);
|
||||
}
|
||||
|
||||
public Task<Models.PremiumArea> UpdatePremiumAreaAsync(Models.PremiumArea PremiumArea)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, PremiumArea.ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
PremiumArea = _PremiumAreaRepository.UpdatePremiumArea(PremiumArea);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "PremiumArea Updated {PremiumArea}", PremiumArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PremiumArea Update Attempt {PremiumArea}", PremiumArea);
|
||||
PremiumArea = null;
|
||||
}
|
||||
return Task.FromResult(PremiumArea);
|
||||
}
|
||||
|
||||
public Task DeletePremiumAreaAsync(int PremiumAreaId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
_PremiumAreaRepository.DeletePremiumArea(PremiumAreaId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "PremiumArea Deleted {PremiumAreaId}", PremiumAreaId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PremiumArea Delete Attempt {PremiumAreaId} {ModuleId}", PremiumAreaId, ModuleId);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user