New: Report-System using globally available Interfaces.
This commit is contained in:
117
Server/Controllers/ReportSystemController.cs
Normal file
117
Server/Controllers/ReportSystemController.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Services;
|
||||
using Oqtane.Controllers;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Models;
|
||||
using Oqtane.Models;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Services;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class ReportSystemController : ModuleControllerBase
|
||||
{
|
||||
private readonly IReportSystemReportingService _reportSystemReportingService;
|
||||
|
||||
public ReportSystemController(IReportSystemReportingService reportSystemReportingService, ILogManager logger, IHttpContextAccessor accessor) : base(logger, accessor)
|
||||
{
|
||||
_reportSystemReportingService = reportSystemReportingService;
|
||||
}
|
||||
|
||||
// GET: api/<controller>?moduleid=x
|
||||
[HttpGet]
|
||||
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||
public async Task<IEnumerable<Reporting>> Get(string moduleid)
|
||||
{
|
||||
int ModuleId;
|
||||
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
|
||||
{
|
||||
return await _reportSystemReportingService.GetReportsAsync(ModuleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Get Attempt {ModuleId}", moduleid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("get/{id}/{moduleid}")]
|
||||
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||
public async Task<Reporting> Get(int id, int moduleid)
|
||||
{
|
||||
if (IsAuthorizedEntityId(EntityNames.Module, moduleid))
|
||||
{
|
||||
return await _reportSystemReportingService.GetReportAsync(id, moduleid);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Get Attempt {Reporting} {ModuleId}", id, moduleid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Policy = PolicyNames.EditModule)]
|
||||
public async Task<Reporting> Post([FromBody] Reporting Reporting)
|
||||
{
|
||||
if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, Reporting.ModuleId))
|
||||
{
|
||||
Reporting = await _reportSystemReportingService.CreateReportAsync(Reporting);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Post Attempt {Reporting}", Reporting);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
Reporting = null;
|
||||
}
|
||||
return Reporting;
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Policy = PolicyNames.EditModule)]
|
||||
public async Task<Reporting> Put(int id, [FromBody] Reporting Reporting)
|
||||
{
|
||||
if (ModelState.IsValid && Reporting.ReportingID == id && IsAuthorizedEntityId(EntityNames.Module, Reporting.ReportingID))
|
||||
{
|
||||
Reporting = await _reportSystemReportingService.UpdateReport(Reporting);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Put Attempt {Reporting}", Reporting);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
Reporting = null;
|
||||
}
|
||||
return Reporting;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}/{moduleid}")]
|
||||
[Authorize(Policy = PolicyNames.EditModule)]
|
||||
public async Task Delete(int id, int moduleid)
|
||||
{
|
||||
Reporting Reporting = await _reportSystemReportingService.GetReportAsync(id, moduleid);
|
||||
if (Reporting != null && IsAuthorizedEntityId(EntityNames.Module, Reporting.ReportingID))
|
||||
{
|
||||
await _reportSystemReportingService.DeleteReportingAsync(id, Reporting.ReportingID);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Delete Attempt {ReportingID} {ModuleId}", id, moduleid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Server/Manager/ReportSystemManager.cs
Normal file
76
Server/Manager/ReportSystemManager.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Repository;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
using System.Threading.Tasks;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Repository;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Services;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Manager
|
||||
{
|
||||
public class ReportSystemManager : MigratableModuleBase, IInstallable, IPortable, ISearchable
|
||||
{
|
||||
private readonly IReportingRepository _reportSystemRepository;
|
||||
private readonly IDBContextDependencies _DBContextDependencies;
|
||||
|
||||
public ReportSystemManager(IReportingRepository reportSystemRepository, IDBContextDependencies DBContextDependencies)
|
||||
{
|
||||
_reportSystemRepository = reportSystemRepository;
|
||||
_DBContextDependencies = DBContextDependencies;
|
||||
}
|
||||
|
||||
public bool Install(Tenant tenant, string version)
|
||||
{
|
||||
Console.WriteLine("Installing ReportSystem module for tenant {TenantId}");
|
||||
return Migrate(new ReportingContext(_DBContextDependencies), tenant, MigrationType.Up);
|
||||
}
|
||||
|
||||
public bool Uninstall(Tenant tenant)
|
||||
{
|
||||
return Migrate(new ReportingContext(_DBContextDependencies), tenant, MigrationType.Down);
|
||||
}
|
||||
|
||||
public string ExportModule(Oqtane.Models.Module module)
|
||||
{
|
||||
string content = "";
|
||||
List<Reporting> reportings = _reportSystemRepository.GetReportings().ToList();
|
||||
if (reportings != null)
|
||||
{
|
||||
content = JsonSerializer.Serialize(reportings);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
public void ImportModule(Oqtane.Models.Module module, string content, string version)
|
||||
{
|
||||
List<Reporting> reportings = null;
|
||||
if (!string.IsNullOrEmpty(content))
|
||||
{
|
||||
reportings = JsonSerializer.Deserialize<List<Reporting>>(content);
|
||||
}
|
||||
if (reportings != null)
|
||||
{
|
||||
foreach(var reporting in reportings)
|
||||
{
|
||||
_reportSystemRepository.AddReporting(reporting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task<List<SearchContent>> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn)
|
||||
{
|
||||
var searchContentList = new List<SearchContent>();
|
||||
|
||||
return Task.FromResult(searchContentList);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Server/Migrations/EntityBuilders/ReportingEntityBuilder.cs
Normal file
37
Server/Migrations/EntityBuilders/ReportingEntityBuilder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Migrations.EntityBuilders;
|
||||
|
||||
public class ReportingEntityBuilder : AuditableBaseEntityBuilder<ReportingEntityBuilder>
|
||||
{
|
||||
private const string _entityTableName = "SZUAbsolventenvereinReportings";
|
||||
private readonly PrimaryKey<ReportingEntityBuilder> _primaryKey = new ("PK_ReportingEntityBuilder", x => x.ReportingID);
|
||||
|
||||
public ReportingEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
|
||||
{
|
||||
EntityTableName = _entityTableName;
|
||||
PrimaryKey = _primaryKey;
|
||||
}
|
||||
|
||||
protected override ReportingEntityBuilder BuildTable(ColumnsBuilder table)
|
||||
{
|
||||
ReportingID = AddAutoIncrementColumn(table, "ReportingID");
|
||||
ModuleId = AddIntegerColumn(table, "ModuleId");
|
||||
EntityId = AddIntegerColumn(table, "EntityId");
|
||||
Note = AddMaxStringColumn(table, "Note");
|
||||
Reason = AddMaxStringColumn(table, "Reason");
|
||||
AddAuditableColumns(table);
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperationBuilder<AddColumnOperation> ReportingID { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> ModuleId { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> EntityId { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> Note { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> Reason { get; set; }
|
||||
}
|
||||
30
Server/Migrations/ReportSystem/01000000_InitializeModule.cs
Normal file
30
Server/Migrations/ReportSystem/01000000_InitializeModule.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Migrations.EntityBuilders;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Migrations
|
||||
{
|
||||
[DbContext(typeof(ReportingContext))]
|
||||
[Migration("SZUAbsolventenverein.Module.ReportSystem.01.00.00.00")]
|
||||
public class InitializeModule : MultiDatabaseMigration
|
||||
{
|
||||
public InitializeModule(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var entityBuilder = new ReportingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.Create();
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var entityBuilder = new ReportingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.Drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Server/Repository/AdminModules/AdminModulesContext.cs
Normal file
27
Server/Repository/AdminModules/AdminModulesContext.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Repository
|
||||
{
|
||||
public class AdminModulesContext : DBContextBase, ITransientService, IMultiDatabase
|
||||
{
|
||||
public virtual DbSet<Models.AdminModules> AdminModules { get; set; }
|
||||
|
||||
public AdminModulesContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
|
||||
{
|
||||
// ContextBase handles multi-tenant database connections
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<Models.AdminModules>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinAdminModules"));
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Server/Repository/AdminModules/AdminModulesRepository.cs
Normal file
75
Server/Repository/AdminModules/AdminModulesRepository.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Modules;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Repository
|
||||
{
|
||||
public interface IAdminModulesRepository
|
||||
{
|
||||
IEnumerable<Models.AdminModules> GetAdminModuless(int ModuleId);
|
||||
Models.AdminModules GetAdminModules(int AdminModulesId);
|
||||
Models.AdminModules GetAdminModules(int AdminModulesId, bool tracking);
|
||||
Models.AdminModules AddAdminModules(Models.AdminModules AdminModules);
|
||||
Models.AdminModules UpdateAdminModules(Models.AdminModules AdminModules);
|
||||
void DeleteAdminModules(int AdminModulesId);
|
||||
}
|
||||
|
||||
public class AdminModulesRepository : IAdminModulesRepository, ITransientService
|
||||
{
|
||||
private readonly IDbContextFactory<AdminModulesContext> _factory;
|
||||
|
||||
public AdminModulesRepository(IDbContextFactory<AdminModulesContext> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
public IEnumerable<Models.AdminModules> GetAdminModuless(int ModuleId)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
return db.AdminModules.Where(item => item.ModuleId == ModuleId).ToList();
|
||||
}
|
||||
|
||||
public Models.AdminModules GetAdminModules(int AdminModulesId)
|
||||
{
|
||||
return GetAdminModules(AdminModulesId, true);
|
||||
}
|
||||
|
||||
public Models.AdminModules GetAdminModules(int AdminModulesId, bool tracking)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
if (tracking)
|
||||
{
|
||||
return db.AdminModules.Find(AdminModulesId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.AdminModules.AsNoTracking().FirstOrDefault(item => item.AdminModulesId == AdminModulesId);
|
||||
}
|
||||
}
|
||||
|
||||
public Models.AdminModules AddAdminModules(Models.AdminModules AdminModules)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.AdminModules.Add(AdminModules);
|
||||
db.SaveChanges();
|
||||
return AdminModules;
|
||||
}
|
||||
|
||||
public Models.AdminModules UpdateAdminModules(Models.AdminModules AdminModules)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Entry(AdminModules).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return AdminModules;
|
||||
}
|
||||
|
||||
public void DeleteAdminModules(int AdminModulesId)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
Models.AdminModules AdminModules = db.AdminModules.Find(AdminModulesId);
|
||||
db.AdminModules.Remove(AdminModules);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Server/Repository/ReportingSystem/ReportingContext.cs
Normal file
24
Server/Repository/ReportingSystem/ReportingContext.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Repository
|
||||
{
|
||||
public class ReportingContext : DBContextBase, ITransientService, IMultiDatabase
|
||||
{
|
||||
public virtual DbSet<Reporting> Reportings { get; set; }
|
||||
|
||||
public ReportingContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
|
||||
{}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
builder.Entity<Reporting>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinReportings"));
|
||||
}
|
||||
}
|
||||
}
|
||||
77
Server/Repository/ReportingSystem/ReportingRepository.cs
Normal file
77
Server/Repository/ReportingSystem/ReportingRepository.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Modules;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Repository
|
||||
{
|
||||
public interface IReportingRepository
|
||||
{
|
||||
IEnumerable<Reporting> GetReportings();
|
||||
Reporting GetReporting(int ReportingID);
|
||||
Reporting GetReporting(int ReportingID, bool tracking);
|
||||
Reporting AddReporting(Reporting Reporting);
|
||||
Reporting UpdateReporting(Reporting Reporting);
|
||||
void DeleteReporting(int ReportingID);
|
||||
}
|
||||
|
||||
public class ReportingRepository : IReportingRepository, ITransientService
|
||||
{
|
||||
private readonly IDbContextFactory<ReportingContext> _factory;
|
||||
|
||||
public ReportingRepository(IDbContextFactory<ReportingContext> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
public IEnumerable<Reporting> GetReportings()
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
return db.Reportings.ToList();
|
||||
}
|
||||
|
||||
public Reporting GetReporting(int ReportingID)
|
||||
{
|
||||
return GetReporting(ReportingID, true);
|
||||
}
|
||||
|
||||
public Reporting GetReporting(int ReportingID, bool tracking)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
if (tracking)
|
||||
{
|
||||
return db.Reportings.Find(ReportingID);
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.Reportings.AsNoTracking().FirstOrDefault(item => item.ReportingID == ReportingID);
|
||||
}
|
||||
}
|
||||
|
||||
public Reporting AddReporting(Reporting Reporting)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Reportings.Add(Reporting);
|
||||
db.SaveChanges();
|
||||
return Reporting;
|
||||
}
|
||||
|
||||
public Reporting UpdateReporting(Reporting Reporting)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Entry(Reporting).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Reporting;
|
||||
}
|
||||
|
||||
public void DeleteReporting(int ReportingID)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
var Reporting = db.Reportings.Find(ReportingID);
|
||||
db.Reportings.Remove(Reporting);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Interfaces">
|
||||
<HintPath>..\..\interfaces\Interfaces\bin\Debug\net10.0\Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Oqtane.Server"><HintPath>..\..\oqtane.framework\Oqtane.Server\bin\Debug\net10.0\Oqtane.Server.dll</HintPath></Reference>
|
||||
<Reference Include="Oqtane.Shared"><HintPath>..\..\oqtane.framework\Oqtane.Server\bin\Debug\net10.0\Oqtane.Shared.dll</HintPath></Reference>
|
||||
</ItemGroup>
|
||||
|
||||
119
Server/Services/ReportSystemReportingService.cs
Normal file
119
Server/Services/ReportSystemReportingService.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Shared;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Models;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.ReportSystem.Services
|
||||
{
|
||||
public class ServerReportSystemReportingService : IReportSystemReportingService, IReportingHandler
|
||||
{
|
||||
private readonly IReportingRepository _reportSystemRepository;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public ServerReportSystemReportingService(IReportingRepository reportSystemRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
||||
{
|
||||
_reportSystemRepository = reportSystemRepository;
|
||||
_userPermissions = userPermissions;
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
public Task<Reporting> CreateReportAsync(Reporting Reporting)
|
||||
{
|
||||
// true ||
|
||||
Console.WriteLine("HELP");
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.ModuleDefinition, 53, PermissionNames.Utilize))
|
||||
{
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Reporting Updated {Reporting}", Reporting);
|
||||
return Task.FromResult(_reportSystemRepository.AddReporting(Reporting));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Update Attempt {Reporting}", Reporting);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<List<Reporting>> GetReportsAsync(int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
return Task.FromResult(_reportSystemRepository.GetReportings().ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reportings Get Attempt {ModuleId}", ModuleId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Reporting> GetReportAsync(int ReportableId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
return Task.FromResult(_reportSystemRepository.GetReporting(ReportableId));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Get Attempt {ModuleId} {ReportableId}", ModuleId, ReportableId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Reporting> UpdateReport(Reporting Reporting)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, Reporting.ReportingID, PermissionNames.Edit))
|
||||
{
|
||||
Reporting = _reportSystemRepository.UpdateReporting(Reporting);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Reporting Updated {Reporting}", Reporting);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Update Attempt {Reporting}", Reporting);
|
||||
Reporting = null;
|
||||
}
|
||||
|
||||
return Task.FromResult(Reporting);
|
||||
}
|
||||
|
||||
public Task DeleteReportingAsync(int ReportingId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
_reportSystemRepository.DeleteReporting(ReportingId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Reporting Deleted {ReportingId}", ReportingId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Delete Attempt {ReportingId} {ModuleId}", ReportingId, ModuleId);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async void Report(IReportable reportable, string note)
|
||||
{
|
||||
// if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
Reporting reporting = await CreateReportAsync(new Reporting {ModuleId = reportable.ModuleID, EntityId = reportable.EntityID, Note = note, Reason = "Default Reason"});
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Reporting recieved {ReportingId}", reporting.ReportingID);
|
||||
}
|
||||
// else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Reporting Delete Attempt {EntityId} {ModuleId}", reportable.EntityID, reportable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
using Interfaces;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Infrastructure;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Services;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Repository;
|
||||
using SZUAbsolventenverein.Module.ReportSystem.Services;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Startup
|
||||
{
|
||||
@@ -22,7 +25,10 @@ namespace SZUAbsolventenverein.Module.AdminModules.Startup
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IAdminModulesService, ServerAdminModulesService>();
|
||||
services.AddTransient<IReportSystemReportingService, ServerReportSystemReportingService>();
|
||||
services.AddTransient<IReportingHandler, ServerReportSystemReportingService>();
|
||||
services.AddDbContextFactory<AdminModulesContext>(opt => { }, ServiceLifetime.Transient);
|
||||
services.AddDbContextFactory<ReportingContext>(opt => { }, ServiceLifetime.Transient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user