Add project files.

This commit is contained in:
Adams
2025-04-07 11:47:28 +02:00
parent 616c50c0b9
commit 796a98dd89
42 changed files with 1871 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Version>1.0.0</Version>
<Product>AdamGais.Module.AnmeldeTool</Product>
<Authors>AdamGais</Authors>
<Company>AdamGais</Company>
<Description>AnmeldeTool</Description>
<Copyright>AdamGais</Copyright>
<AssemblyName>AdamGais.Module.AnmeldeTool.Server.Oqtane</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot\_content\**\*.*" />
<None Include="wwwroot\_content\**\*.*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\AdamGais.Module.AnmeldeTool.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Oqtane.Server"><HintPath>..\..\oqtane.framework-dev\Oqtane.Server\bin\Debug\net9.0\Oqtane.Server.dll</HintPath></Reference>
<Reference Include="Oqtane.Shared"><HintPath>..\..\oqtane.framework-dev\Oqtane.Server\bin\Debug\net9.0\Oqtane.Shared.dll</HintPath></Reference>
</ItemGroup>
</Project>

View File

@ -0,0 +1,114 @@
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 AdamGais.Module.AnmeldeTool.Services;
using Oqtane.Controllers;
using System.Net;
using System.Threading.Tasks;
namespace AdamGais.Module.AnmeldeTool.Controllers
{
[Route(ControllerRoutes.ApiRoute)]
public class AnmeldeToolController : ModuleControllerBase
{
private readonly IAnmeldeToolService _AnmeldeToolService;
public AnmeldeToolController(IAnmeldeToolService AnmeldeToolService, ILogManager logger, IHttpContextAccessor accessor) : base(logger, accessor)
{
_AnmeldeToolService = AnmeldeToolService;
}
// GET: api/<controller>?moduleid=x
[HttpGet]
[Authorize(Policy = PolicyNames.ViewModule)]
public async Task<IEnumerable<Models.AnmeldeTool>> Get(string moduleid)
{
int ModuleId;
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
{
return await _AnmeldeToolService.GetAnmeldeToolsAsync(ModuleId);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Get Attempt {ModuleId}", moduleid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
}
// GET api/<controller>/5
[HttpGet("{id}/{moduleid}")]
[Authorize(Policy = PolicyNames.ViewModule)]
public async Task<Models.AnmeldeTool> Get(int id, int moduleid)
{
Models.AnmeldeTool AnmeldeTool = await _AnmeldeToolService.GetAnmeldeToolAsync(id, moduleid);
if (AnmeldeTool != null && IsAuthorizedEntityId(EntityNames.Module, AnmeldeTool.ModuleId))
{
return AnmeldeTool;
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Get Attempt {AnmeldeToolId} {ModuleId}", id, moduleid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
}
// POST api/<controller>
[HttpPost]
[Authorize(Policy = PolicyNames.EditModule)]
public async Task<Models.AnmeldeTool> Post([FromBody] Models.AnmeldeTool AnmeldeTool)
{
if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, AnmeldeTool.ModuleId))
{
AnmeldeTool = await _AnmeldeToolService.AddAnmeldeToolAsync(AnmeldeTool);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Post Attempt {AnmeldeTool}", AnmeldeTool);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
AnmeldeTool = null;
}
return AnmeldeTool;
}
// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(Policy = PolicyNames.EditModule)]
public async Task<Models.AnmeldeTool> Put(int id, [FromBody] Models.AnmeldeTool AnmeldeTool)
{
if (ModelState.IsValid && AnmeldeTool.AnmeldeToolId == id && IsAuthorizedEntityId(EntityNames.Module, AnmeldeTool.ModuleId))
{
AnmeldeTool = await _AnmeldeToolService.UpdateAnmeldeToolAsync(AnmeldeTool);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Put Attempt {AnmeldeTool}", AnmeldeTool);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
AnmeldeTool = null;
}
return AnmeldeTool;
}
// DELETE api/<controller>/5
[HttpDelete("{id}/{moduleid}")]
[Authorize(Policy = PolicyNames.EditModule)]
public async Task Delete(int id, int moduleid)
{
Models.AnmeldeTool AnmeldeTool = await _AnmeldeToolService.GetAnmeldeToolAsync(id, moduleid);
if (AnmeldeTool != null && IsAuthorizedEntityId(EntityNames.Module, AnmeldeTool.ModuleId))
{
await _AnmeldeToolService.DeleteAnmeldeToolAsync(id, AnmeldeTool.ModuleId);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Delete Attempt {AnmeldeToolId} {ModuleId}", id, moduleid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
}
}
}
}

View File

@ -0,0 +1,87 @@
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 AdamGais.Module.AnmeldeTool.Repository;
using System.Threading.Tasks;
namespace AdamGais.Module.AnmeldeTool.Manager
{
public class AnmeldeToolManager : MigratableModuleBase, IInstallable, IPortable, ISearchable
{
private readonly IAnmeldeToolRepository _AnmeldeToolRepository;
private readonly IDBContextDependencies _DBContextDependencies;
public AnmeldeToolManager(IAnmeldeToolRepository AnmeldeToolRepository, IDBContextDependencies DBContextDependencies)
{
_AnmeldeToolRepository = AnmeldeToolRepository;
_DBContextDependencies = DBContextDependencies;
}
public bool Install(Tenant tenant, string version)
{
return Migrate(new AnmeldeToolContext(_DBContextDependencies), tenant, MigrationType.Up);
}
public bool Uninstall(Tenant tenant)
{
return Migrate(new AnmeldeToolContext(_DBContextDependencies), tenant, MigrationType.Down);
}
public string ExportModule(Oqtane.Models.Module module)
{
string content = "";
List<Models.AnmeldeTool> AnmeldeTools = _AnmeldeToolRepository.GetAnmeldeTools(module.ModuleId).ToList();
if (AnmeldeTools != null)
{
content = JsonSerializer.Serialize(AnmeldeTools);
}
return content;
}
public void ImportModule(Oqtane.Models.Module module, string content, string version)
{
List<Models.AnmeldeTool> AnmeldeTools = null;
if (!string.IsNullOrEmpty(content))
{
AnmeldeTools = JsonSerializer.Deserialize<List<Models.AnmeldeTool>>(content);
}
if (AnmeldeTools != null)
{
foreach(var AnmeldeTool in AnmeldeTools)
{
_AnmeldeToolRepository.AddAnmeldeTool(new Models.AnmeldeTool { ModuleId = module.ModuleId, Name = AnmeldeTool.Name });
}
}
}
public Task<List<SearchContent>> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn)
{
var searchContentList = new List<SearchContent>();
foreach (var AnmeldeTool in _AnmeldeToolRepository.GetAnmeldeTools(pageModule.ModuleId))
{
if (AnmeldeTool.ModifiedOn >= lastIndexedOn)
{
searchContentList.Add(new SearchContent
{
EntityName = "AdamGaisAnmeldeTool",
EntityId = AnmeldeTool.AnmeldeToolId.ToString(),
Title = AnmeldeTool.Name,
Body = AnmeldeTool.Name,
ContentModifiedBy = AnmeldeTool.ModifiedBy,
ContentModifiedOn = AnmeldeTool.ModifiedOn
});
}
}
return Task.FromResult(searchContentList);
}
}
}

View File

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Databases.Interfaces;
using Oqtane.Migrations;
using AdamGais.Module.AnmeldeTool.Migrations.EntityBuilders;
using AdamGais.Module.AnmeldeTool.Repository;
namespace AdamGais.Module.AnmeldeTool.Migrations
{
[DbContext(typeof(AnmeldeToolContext))]
[Migration("AdamGais.Module.AnmeldeTool.01.00.00.00")]
public class InitializeModule : MultiDatabaseMigration
{
public InitializeModule(IDatabase database) : base(database)
{
}
protected override void Up(MigrationBuilder migrationBuilder)
{
var entityBuilder = new AnmeldeToolEntityBuilder(migrationBuilder, ActiveDatabase);
entityBuilder.Create();
}
protected override void Down(MigrationBuilder migrationBuilder)
{
var entityBuilder = new AnmeldeToolEntityBuilder(migrationBuilder, ActiveDatabase);
entityBuilder.Drop();
}
}
}

View File

@ -0,0 +1,36 @@
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 AdamGais.Module.AnmeldeTool.Migrations.EntityBuilders
{
public class AnmeldeToolEntityBuilder : AuditableBaseEntityBuilder<AnmeldeToolEntityBuilder>
{
private const string _entityTableName = "AdamGaisAnmeldeTool";
private readonly PrimaryKey<AnmeldeToolEntityBuilder> _primaryKey = new("PK_AdamGaisAnmeldeTool", x => x.AnmeldeToolId);
private readonly ForeignKey<AnmeldeToolEntityBuilder> _moduleForeignKey = new("FK_AdamGaisAnmeldeTool_Module", x => x.ModuleId, "Module", "ModuleId", ReferentialAction.Cascade);
public AnmeldeToolEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
{
EntityTableName = _entityTableName;
PrimaryKey = _primaryKey;
ForeignKeys.Add(_moduleForeignKey);
}
protected override AnmeldeToolEntityBuilder BuildTable(ColumnsBuilder table)
{
AnmeldeToolId = AddAutoIncrementColumn(table,"AnmeldeToolId");
ModuleId = AddIntegerColumn(table,"ModuleId");
Name = AddMaxStringColumn(table,"Name");
AddAuditableColumns(table);
return this;
}
public OperationBuilder<AddColumnOperation> AnmeldeToolId { get; set; }
public OperationBuilder<AddColumnOperation> ModuleId { get; set; }
public OperationBuilder<AddColumnOperation> Name { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Oqtane.Modules;
using Oqtane.Repository;
using Oqtane.Infrastructure;
using Oqtane.Repository.Databases.Interfaces;
namespace AdamGais.Module.AnmeldeTool.Repository
{
public class AnmeldeToolContext : DBContextBase, ITransientService, IMultiDatabase
{
public virtual DbSet<Models.AnmeldeTool> AnmeldeTool { get; set; }
public AnmeldeToolContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
{
// ContextBase handles multi-tenant database connections
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Models.AnmeldeTool>().ToTable(ActiveDatabase.RewriteName("AdamGaisAnmeldeTool"));
}
}
}

View File

@ -0,0 +1,65 @@
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Collections.Generic;
using Oqtane.Modules;
namespace AdamGais.Module.AnmeldeTool.Repository
{
public class AnmeldeToolRepository : IAnmeldeToolRepository, ITransientService
{
private readonly IDbContextFactory<AnmeldeToolContext> _factory;
public AnmeldeToolRepository(IDbContextFactory<AnmeldeToolContext> factory)
{
_factory = factory;
}
public IEnumerable<Models.AnmeldeTool> GetAnmeldeTools(int ModuleId)
{
using var db = _factory.CreateDbContext();
return db.AnmeldeTool.Where(item => item.ModuleId == ModuleId).ToList();
}
public Models.AnmeldeTool GetAnmeldeTool(int AnmeldeToolId)
{
return GetAnmeldeTool(AnmeldeToolId, true);
}
public Models.AnmeldeTool GetAnmeldeTool(int AnmeldeToolId, bool tracking)
{
using var db = _factory.CreateDbContext();
if (tracking)
{
return db.AnmeldeTool.Find(AnmeldeToolId);
}
else
{
return db.AnmeldeTool.AsNoTracking().FirstOrDefault(item => item.AnmeldeToolId == AnmeldeToolId);
}
}
public Models.AnmeldeTool AddAnmeldeTool(Models.AnmeldeTool AnmeldeTool)
{
using var db = _factory.CreateDbContext();
db.AnmeldeTool.Add(AnmeldeTool);
db.SaveChanges();
return AnmeldeTool;
}
public Models.AnmeldeTool UpdateAnmeldeTool(Models.AnmeldeTool AnmeldeTool)
{
using var db = _factory.CreateDbContext();
db.Entry(AnmeldeTool).State = EntityState.Modified;
db.SaveChanges();
return AnmeldeTool;
}
public void DeleteAnmeldeTool(int AnmeldeToolId)
{
using var db = _factory.CreateDbContext();
Models.AnmeldeTool AnmeldeTool = db.AnmeldeTool.Find(AnmeldeToolId);
db.AnmeldeTool.Remove(AnmeldeTool);
db.SaveChanges();
}
}
}

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace AdamGais.Module.AnmeldeTool.Repository
{
public interface IAnmeldeToolRepository
{
IEnumerable<Models.AnmeldeTool> GetAnmeldeTools(int ModuleId);
Models.AnmeldeTool GetAnmeldeTool(int AnmeldeToolId);
Models.AnmeldeTool GetAnmeldeTool(int AnmeldeToolId, bool tracking);
Models.AnmeldeTool AddAnmeldeTool(Models.AnmeldeTool AnmeldeTool);
Models.AnmeldeTool UpdateAnmeldeTool(Models.AnmeldeTool AnmeldeTool);
void DeleteAnmeldeTool(int AnmeldeToolId);
}
}

View 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 AdamGais.Module.AnmeldeTool.Repository;
namespace AdamGais.Module.AnmeldeTool.Services
{
public class ServerAnmeldeToolService : IAnmeldeToolService
{
private readonly IAnmeldeToolRepository _AnmeldeToolRepository;
private readonly IUserPermissions _userPermissions;
private readonly ILogManager _logger;
private readonly IHttpContextAccessor _accessor;
private readonly Alias _alias;
public ServerAnmeldeToolService(IAnmeldeToolRepository AnmeldeToolRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
{
_AnmeldeToolRepository = AnmeldeToolRepository;
_userPermissions = userPermissions;
_logger = logger;
_accessor = accessor;
_alias = tenantManager.GetAlias();
}
public Task<List<Models.AnmeldeTool>> GetAnmeldeToolsAsync(int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_AnmeldeToolRepository.GetAnmeldeTools(ModuleId).ToList());
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<Models.AnmeldeTool> GetAnmeldeToolAsync(int AnmeldeToolId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_AnmeldeToolRepository.GetAnmeldeTool(AnmeldeToolId));
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Get Attempt {AnmeldeToolId} {ModuleId}", AnmeldeToolId, ModuleId);
return null;
}
}
public Task<Models.AnmeldeTool> AddAnmeldeToolAsync(Models.AnmeldeTool AnmeldeTool)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, AnmeldeTool.ModuleId, PermissionNames.Edit))
{
AnmeldeTool = _AnmeldeToolRepository.AddAnmeldeTool(AnmeldeTool);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "AnmeldeTool Added {AnmeldeTool}", AnmeldeTool);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Add Attempt {AnmeldeTool}", AnmeldeTool);
AnmeldeTool = null;
}
return Task.FromResult(AnmeldeTool);
}
public Task<Models.AnmeldeTool> UpdateAnmeldeToolAsync(Models.AnmeldeTool AnmeldeTool)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, AnmeldeTool.ModuleId, PermissionNames.Edit))
{
AnmeldeTool = _AnmeldeToolRepository.UpdateAnmeldeTool(AnmeldeTool);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "AnmeldeTool Updated {AnmeldeTool}", AnmeldeTool);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Update Attempt {AnmeldeTool}", AnmeldeTool);
AnmeldeTool = null;
}
return Task.FromResult(AnmeldeTool);
}
public Task DeleteAnmeldeToolAsync(int AnmeldeToolId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
{
_AnmeldeToolRepository.DeleteAnmeldeTool(AnmeldeToolId);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "AnmeldeTool Deleted {AnmeldeToolId}", AnmeldeToolId);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized AnmeldeTool Delete Attempt {AnmeldeToolId} {ModuleId}", AnmeldeToolId, ModuleId);
}
return Task.CompletedTask;
}
}
}

View File

@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Oqtane.Infrastructure;
using AdamGais.Module.AnmeldeTool.Repository;
using AdamGais.Module.AnmeldeTool.Services;
namespace AdamGais.Module.AnmeldeTool.Startup
{
public class ServerStartup : IServerStartup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// not implemented
}
public void ConfigureMvc(IMvcBuilder mvcBuilder)
{
// not implemented
}
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IAnmeldeToolService, ServerAnmeldeToolService>();
services.AddDbContextFactory<AnmeldeToolContext>(opt => { }, ServiceLifetime.Transient);
}
}
}

View File

@ -0,0 +1 @@
/* Module Custom Styles */

View File

@ -0,0 +1,5 @@
/* Module Script */
var AdamGais = AdamGais || {};
AdamGais.AnmeldeTool = {
};

View File

@ -0,0 +1,11 @@
The _content folder should only contain static resources from shared razor component libraries (RCLs). Static resources can be extracted from shared RCL Nuget packages by executing a Publish task on the module's Server project to a local folder and copying the files from the _content folder which is created. Each shared RCL would have its own appropriately named subfolder within the module's _content folder.
ie.
/_content
/Radzen.Blazor
/css
/fonts
/syncfusion.blazor
/scripts
/styles