Feature: Hall of Fame Module Implementation (1.0.1)

- Added Hall of Fame module logic (Models, Controller, Service).
- Implemented 'One Entry Per User' and 'Publish/Draft' workflow.
- Updated UI to Grid Layout (Index.razor) and Unified Form (Edit.razor).
- Added Database Migration 01000001 for new columns.
- Bumped version to 1.0.1.
This commit is contained in:
Adam Gaiswinkler
2026-01-15 00:01:55 +01:00
parent 5dfa690432
commit 7114904412
12 changed files with 378 additions and 55 deletions

View File

@@ -10,15 +10,54 @@
<form @ref="form" class="@(validated ? " was-validated" : "needs-validation" )" novalidate> <form @ref="form" class="@(validated ? " was-validated" : "needs-validation" )" novalidate>
<div class="container"> <div class="container">
<div class="row mb-1 align-items-center"> <div class="row mb-3 align-items-center">
<Label Class="col-sm-3" For="name" HelpText="Enter a name" ResourceKey="Name">Name: </Label> <Label Class="col-sm-3 col-form-label" For="name" HelpText="Gib deinen Namen ein" ResourceKey="Name">Name: </Label>
<div class="col-sm-9"> <div class="col-sm-9">
<input id="name" class="form-control" @bind="@_name" required /> <input id="name" class="form-control" @bind="@_name" required maxlength="120" />
<div class="invalid-feedback">Bitte gib einen Namen ein (max. 120 Zeichen).</div>
</div>
</div>
<div class="row mb-3 align-items-center">
<Label Class="col-sm-3 col-form-label" For="year" HelpText="Jahrgang (z.B. 2020)" ResourceKey="Year">Jahrgang: </Label>
<div class="col-sm-9">
<input id="year" type="number" class="form-control" @bind="@_year" required min="1990" max="2100" />
<div class="invalid-feedback">Bitte gib einen gültigen Jahrgang ein.</div>
</div>
</div>
<div class="row mb-3 align-items-center">
<Label Class="col-sm-3 col-form-label" For="description" HelpText="Kurzbeschreibung / Werdegang" ResourceKey="Description">Beschreibung: </Label>
<div class="col-sm-9">
<textarea id="description" class="form-control" @bind="@_description" required rows="5" maxlength="1500"></textarea>
<div class="invalid-feedback">Bitte gib eine Beschreibung ein.</div>
</div>
</div>
<div class="row mb-3 align-items-center">
<Label Class="col-sm-3 col-form-label" For="image" HelpText="Bild URL (optional)" ResourceKey="Image">Bild URL: </Label>
<div class="col-sm-9">
<input id="image" class="form-control" @bind="@_image" />
</div>
</div>
<div class="row mb-3 align-items-center">
<Label Class="col-sm-3 col-form-label" For="link" HelpText="Externer Link (optional)" ResourceKey="Link">Link: </Label>
<div class="col-sm-9">
<input id="link" type="url" class="form-control" @bind="@_link" placeholder="https://" />
<div class="invalid-feedback">Bitte gib eine gültige URL ein (startet mit http:// oder https://).</div>
</div>
</div>
<div class="row mb-3 align-items-center">
<Label Class="col-sm-3 col-form-label" For="status" HelpText="Status" ResourceKey="Status">Status: </Label>
<div class="col-sm-9">
<p>Aktuell: <strong>@(_status ?? "Neu")</strong></p>
</div> </div>
</div> </div>
</div> </div>
<button type="button" class="btn btn-success" @onclick="Save">@Localizer["Save"]</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink> <div class="mt-4">
<button type="button" class="btn btn-secondary me-2" @onclick="@(() => Save("Draft"))">Als Entwurf speichern</button>
<button type="button" class="btn btn-primary" @onclick="@(() => Save("Published"))">Veröffentlichen</button>
<NavLink class="btn btn-link ms-2" href="@NavigateUrl()">Abbrechen</NavLink>
</div>
<br /><br /> <br /><br />
@if (PageState.Action == "Edit") @if (PageState.Action == "Edit")
{ {
@@ -27,11 +66,11 @@
</form> </form>
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; // Logic handles checking user own entry
public override string Actions => "Add,Edit"; public override string Actions => "Add,Edit";
public override string Title => "Manage HallOfFame"; public override string Title => "Hall of Fame Eintrag verwalten";
public override List<Resource> Resources => new List<Resource>() public override List<Resource> Resources => new List<Resource>()
{ {
@@ -43,6 +82,12 @@
private int _id; private int _id;
private string _name; private string _name;
private int _year = DateTime.Now.Year;
private string _description;
private string _image;
private string _link;
private string _status = "Draft";
private string _createdby; private string _createdby;
private DateTime _createdon; private DateTime _createdon;
private string _modifiedby; private string _modifiedby;
@@ -56,15 +101,39 @@
{ {
_id = Int32.Parse(PageState.QueryString["id"]); _id = Int32.Parse(PageState.QueryString["id"]);
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId); HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
// Security check: only allow editing own entry
if (HallOfFame != null) if (HallOfFame != null)
{ {
if (HallOfFame.UserId != PageState.User.UserId)
{
NavigationManager.NavigateTo(NavigateUrl());
return;
}
_name = HallOfFame.Name; _name = HallOfFame.Name;
_year = HallOfFame.Year;
_description = HallOfFame.Description;
_image = HallOfFame.Image;
_link = HallOfFame.Link;
_status = HallOfFame.Status;
_createdby = HallOfFame.CreatedBy; _createdby = HallOfFame.CreatedBy;
_createdon = HallOfFame.CreatedOn; _createdon = HallOfFame.CreatedOn;
_modifiedby = HallOfFame.ModifiedBy; _modifiedby = HallOfFame.ModifiedBy;
_modifiedon = HallOfFame.ModifiedOn; _modifiedon = HallOfFame.ModifiedOn;
} }
} }
else // Add Mode
{
// Check if user already has an entry to prevent duplicates
var existing = await HallOfFameService.GetHallOfFameByUserIdAsync(PageState.User.UserId, ModuleState.ModuleId);
if (existing != null)
{
// Use NavigateUrl with parameters properly (simplified here)
NavigationManager.NavigateTo(EditUrl(existing.HallOfFameId.ToString()));
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -73,7 +142,7 @@
} }
} }
private async Task Save() private async Task Save(string status)
{ {
try try
{ {
@@ -81,20 +150,39 @@
var interop = new Oqtane.UI.Interop(JSRuntime); var interop = new Oqtane.UI.Interop(JSRuntime);
if (await interop.FormValid(form)) if (await interop.FormValid(form))
{ {
_status = status;
if (PageState.Action == "Add") if (PageState.Action == "Add")
{ {
HallOfFame HallOfFame = new HallOfFame(); HallOfFame HallOfFame = new HallOfFame();
HallOfFame.ModuleId = ModuleState.ModuleId; HallOfFame.ModuleId = ModuleState.ModuleId;
HallOfFame.UserId = PageState.User.UserId; // Set Owner
HallOfFame.Name = _name; HallOfFame.Name = _name;
HallOfFame.Year = _year;
HallOfFame.Description = _description;
HallOfFame.Image = _image;
HallOfFame.Link = _link;
HallOfFame.Status = _status;
HallOfFame = await HallOfFameService.AddHallOfFameAsync(HallOfFame); HallOfFame = await HallOfFameService.AddHallOfFameAsync(HallOfFame);
await logger.LogInformation("HallOfFame Added {HallOfFame}", HallOfFame); await logger.LogInformation("HallOfFame Added {HallOfFame}", HallOfFame);
} }
else else
{ {
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId); HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
HallOfFame.Name = _name; // Ensure we don't overwrite with invalid user logic, though server checks too
await HallOfFameService.UpdateHallOfFameAsync(HallOfFame); if (HallOfFame.UserId == PageState.User.UserId)
await logger.LogInformation("HallOfFame Updated {HallOfFame}", HallOfFame); {
HallOfFame.Name = _name;
HallOfFame.Year = _year;
HallOfFame.Description = _description;
HallOfFame.Image = _image;
HallOfFame.Link = _link;
HallOfFame.Status = _status;
await HallOfFameService.UpdateHallOfFameAsync(HallOfFame);
await logger.LogInformation("HallOfFame Updated {HallOfFame}", HallOfFame);
}
} }
NavigationManager.NavigateTo(NavigateUrl()); NavigationManager.NavigateTo(NavigateUrl());
} }

View File

@@ -13,27 +13,55 @@
} }
else else
{ {
<ActionLink Action="Add" Security="SecurityAccessLevel.Edit" Text="Add HallOfFame" ResourceKey="Add" /> <div class="row mb-4">
<br /> <div class="col text-end">
<br /> @if (PageState.User != null)
{
if (_myEntry != null)
{
<ActionLink Action="Edit" Parameters="@($"id=" + _myEntry.HallOfFameId.ToString())" Text="Hall-of-Fame-Eintrag bearbeiten" />
}
else
{
<ActionLink Action="Add" Text="Neuen Hall-of-Fame-Eintrag erstellen" />
}
}
else
{
<p class="text-muted">Einloggen, um einen Eintrag zu erstellen.</p>
}
</div>
</div>
@if (@_HallOfFames.Count != 0) @if (@_HallOfFames.Count != 0)
{ {
<Pager Items="@_HallOfFames"> <div class="row">
<Header> @foreach (var item in _HallOfFames)
<th style="width: 1px;">&nbsp;</th> {
<th style="width: 1px;">&nbsp;</th> <div class="col-md-4 mb-3">
<th>@Localizer["Name"]</th> <div class="card h-100">
</Header> @if (!string.IsNullOrEmpty(item.Image))
<Row> {
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.HallOfFameId.ToString())" ResourceKey="Edit" /></td> <img src="@item.Image" class="card-img-top" alt="@item.Name" style="max-height: 200px; object-fit: cover;">
<td><ActionDialog Header="Delete HallOfFame" Message="Are You Sure You Wish To Delete This HallOfFame?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.HallOfFameId.ToString()" /></td> }
<td>@context.Name</td> <div class="card-body">
</Row> <h5 class="card-title">@item.Name (@item.Year)</h5>
</Pager> <p class="card-text">@item.Description</p>
@if (!string.IsNullOrEmpty(item.Link))
{
<a href="@item.Link" target="_blank" class="btn btn-sm btn-outline-primary">Mehr Infos</a>
}
</div>
</div>
</div>
}
</div>
} }
else else
{ {
<p>@Localizer["Message.DisplayNone"]</p> <div class="alert alert-info">
Es sind noch keine Hall-of-Fame-Einträge veröffentlicht.
</div>
} }
} }
@@ -47,12 +75,18 @@ else
}; };
List<HallOfFame> _HallOfFames; List<HallOfFame> _HallOfFames;
HallOfFame _myEntry;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
try try
{ {
_HallOfFames = await HallOfFameService.GetHallOfFamesAsync(ModuleState.ModuleId); _HallOfFames = await HallOfFameService.GetHallOfFamesAsync(ModuleState.ModuleId);
if (PageState.User != null)
{
_myEntry = await HallOfFameService.GetHallOfFameByUserIdAsync(PageState.User.UserId, ModuleState.ModuleId);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -60,20 +94,4 @@ else
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error); AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
} }
} }
private async Task Delete(HallOfFame HallOfFame)
{
try
{
await HallOfFameService.DeleteHallOfFameAsync(HallOfFame.HallOfFameId, ModuleState.ModuleId);
await logger.LogInformation("HallOfFame Deleted {HallOfFame}", HallOfFame);
_HallOfFames = await HallOfFameService.GetHallOfFamesAsync(ModuleState.ModuleId);
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting HallOfFame {HallOfFame} {Error}", HallOfFame, ex.Message);
AddModuleMessage(Localizer["Message.DeleteError"], MessageType.Error);
}
}
} }

View File

@@ -13,6 +13,8 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
Task<Models.HallOfFame> GetHallOfFameAsync(int HallOfFameId, int ModuleId); Task<Models.HallOfFame> GetHallOfFameAsync(int HallOfFameId, int ModuleId);
Task<Models.HallOfFame> GetHallOfFameByUserIdAsync(int UserId, int ModuleId);
Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame); Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame);
Task<Models.HallOfFame> UpdateHallOfFameAsync(Models.HallOfFame HallOfFame); Task<Models.HallOfFame> UpdateHallOfFameAsync(Models.HallOfFame HallOfFame);
@@ -37,6 +39,11 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
return await GetJsonAsync<Models.HallOfFame>(CreateAuthorizationPolicyUrl($"{Apiurl}/{HallOfFameId}/{ModuleId}", EntityNames.Module, ModuleId)); return await GetJsonAsync<Models.HallOfFame>(CreateAuthorizationPolicyUrl($"{Apiurl}/{HallOfFameId}/{ModuleId}", EntityNames.Module, ModuleId));
} }
public async Task<Models.HallOfFame> GetHallOfFameByUserIdAsync(int UserId, int ModuleId)
{
return await GetJsonAsync<Models.HallOfFame>(CreateAuthorizationPolicyUrl($"{Apiurl}/user/{UserId}?moduleid={ModuleId}", EntityNames.Module, ModuleId));
}
public async Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame) public async Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame)
{ {
return await PostJsonAsync<Models.HallOfFame>(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, HallOfFame.ModuleId), HallOfFame); return await PostJsonAsync<Models.HallOfFame>(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, HallOfFame.ModuleId), HallOfFame);

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>$projectname$</id> <id>$projectname$</id>
<version>1.0.0</version> <version>1.0.1</version>
<authors>SZUAbsolventenverein</authors> <authors>SZUAbsolventenverein</authors>
<owners>SZUAbsolventenverein</owners> <owners>SZUAbsolventenverein</owners>
<title>HallOfFame</title> <title>HallOfFame</title>

15
Package/debug.sh Normal file → Executable file
View File

@@ -3,10 +3,11 @@
TargetFramework=$1 TargetFramework=$1
ProjectName=$2 ProjectName=$2
cp -f "../Client/bin/Debug/$TargetFramework/$ProjectName$.Client.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Client/bin/Debug/$TargetFramework/$ProjectName.Client.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -f "../Client/bin/Debug/$TargetFramework/$ProjectName$.Client.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Client/bin/Debug/$TargetFramework/$ProjectName.Client.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName$.Server.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName.Server.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName$.Server.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Server/bin/Debug/$TargetFramework/$ProjectName.Server.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName$.Shared.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName.Shared.Oqtane.dll" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName$.Shared.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/" cp -f "../Shared/bin/Debug/$TargetFramework/$ProjectName.Shared.Oqtane.pdb" "../../oqtane.framework/Oqtane.Server/bin/Debug/$TargetFramework/"
cp -rf "../Server/wwwroot/"* "../../oqtane.framework/Oqtane.Server/wwwroot/_content/%ProjectName%/" mkdir -p "../../oqtane.framework/Oqtane.Server/wwwroot/_content/$ProjectName/"
cp -rf "../Server/wwwroot/"* "../../oqtane.framework/Oqtane.Server/wwwroot/_content/$ProjectName/"

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Oqtane.Shared; using Oqtane.Shared;
using Oqtane.Enums; using Oqtane.Enums;
@@ -22,6 +23,7 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Controllers
_HallOfFameService = HallOfFameService; _HallOfFameService = HallOfFameService;
} }
// GET: api/<controller>?moduleid=x
// GET: api/<controller>?moduleid=x // GET: api/<controller>?moduleid=x
[HttpGet] [HttpGet]
[Authorize(Policy = PolicyNames.ViewModule)] [Authorize(Policy = PolicyNames.ViewModule)]
@@ -30,7 +32,11 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Controllers
int ModuleId; int ModuleId;
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId)) if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
{ {
return await _HallOfFameService.GetHallOfFamesAsync(ModuleId); var list = await _HallOfFameService.GetHallOfFamesAsync(ModuleId);
// Filter: Show only Published unless user has Edit permissions (simplified check for now, can be expanded)
// For now, let's filter in memory or service. The requirement says: "Hauptseite zeigt nur Published".
// We will filter here.
return list.Where(item => item.Status == "Published");
} }
else else
{ {
@@ -58,6 +64,25 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Controllers
} }
} }
// GET api/<controller>/user/5?moduleid=x
[HttpGet("user/{userid}")]
[Authorize(Policy = PolicyNames.ViewModule)]
public async Task<Models.HallOfFame> GetByUserId(int userid, string moduleid)
{
int ModuleId;
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
{
var list = await _HallOfFameService.GetHallOfFamesAsync(ModuleId);
return list.FirstOrDefault(item => item.UserId == userid);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame GetByUserId Attempt {UserId} {ModuleId}", userid, moduleid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
}
// POST api/<controller> // POST api/<controller>
[HttpPost] [HttpPost]
[Authorize(Policy = PolicyNames.EditModule)] [Authorize(Policy = PolicyNames.EditModule)]
@@ -65,6 +90,15 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Controllers
{ {
if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, HallOfFame.ModuleId)) if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, HallOfFame.ModuleId))
{ {
// Enforce one entry per user
var allEntries = await _HallOfFameService.GetHallOfFamesAsync(HallOfFame.ModuleId);
if (allEntries.Any(e => e.UserId == HallOfFame.UserId))
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User {UserId} already has a Hall of Fame entry.", HallOfFame.UserId);
HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
HallOfFame = await _HallOfFameService.AddHallOfFameAsync(HallOfFame); HallOfFame = await _HallOfFameService.AddHallOfFameAsync(HallOfFame);
} }
else else
@@ -83,7 +117,17 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Controllers
{ {
if (ModelState.IsValid && HallOfFame.HallOfFameId == id && IsAuthorizedEntityId(EntityNames.Module, HallOfFame.ModuleId)) if (ModelState.IsValid && HallOfFame.HallOfFameId == id && IsAuthorizedEntityId(EntityNames.Module, HallOfFame.ModuleId))
{ {
HallOfFame = await _HallOfFameService.UpdateHallOfFameAsync(HallOfFame); var existing = await _HallOfFameService.GetHallOfFameAsync(id, HallOfFame.ModuleId);
if (existing != null && existing.UserId == HallOfFame.UserId)
{
HallOfFame = await _HallOfFameService.UpdateHallOfFameAsync(HallOfFame);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Put Attempt by User {UserId} for Entry {HallOfFameId}", HallOfFame.UserId, id);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
HallOfFame = null;
}
} }
else else
{ {

View File

@@ -0,0 +1,130 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Databases.Interfaces;
using Oqtane.Migrations;
using SZUAbsolventenverein.Module.HallOfFame.Migrations.EntityBuilders;
using SZUAbsolventenverein.Module.HallOfFame.Repository;
namespace SZUAbsolventenverein.Module.HallOfFame.Migrations
{
[DbContext(typeof(HallOfFameContext))]
[Migration("SZUAbsolventenverein.Module.HallOfFame.01.00.00.01")]
public class AddHallOfFameColumns : MultiDatabaseMigration
{
public AddHallOfFameColumns(IDatabase database) : base(database)
{
}
protected override void Up(MigrationBuilder migrationBuilder)
{
var entityBuilder = new HallOfFameEntityBuilder(migrationBuilder, ActiveDatabase);
// Add new columns manually since we are upgrading an existing table
// Note: Integer columns are generated as default/nullable depending on definition, Oqtane Helpers handle generic types.
// Using logic similar to Oqtane.Migrations.EntityBuilders
if (ActiveDatabase.Name == "Sqlite") // Sqlite specific or generic
{
// Generic AddColumn: Table, Name, Type, Nullable
// However, Oqtane EntityBuilder usually builds tables.
// We will use migrationBuilder directly via helper if possible or standard AddColumn.
migrationBuilder.AddColumn<int>(
name: "Year",
table: "SZUAbsolventenvereinHallOfFame",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true); // Allow nulls initially or empty? MaxString usually nullable in Oqtane context? Let's check.
migrationBuilder.AddColumn<string>(
name: "Image",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Link",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Status",
table: "SZUAbsolventenvereinHallOfFame",
maxLength: 50,
nullable: true);
migrationBuilder.AddColumn<int>(
name: "UserId",
table: "SZUAbsolventenvereinHallOfFame",
nullable: false,
defaultValue: 0);
}
else
{
// For SQL Server / others, simply use same AddColumn but allow EF Core to handle types
migrationBuilder.AddColumn<int>(
name: "Year",
table: "SZUAbsolventenvereinHallOfFame",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Image",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Link",
table: "SZUAbsolventenvereinHallOfFame",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Status",
table: "SZUAbsolventenvereinHallOfFame",
maxLength: 50,
nullable: true);
migrationBuilder.AddColumn<int>(
name: "UserId",
table: "SZUAbsolventenvereinHallOfFame",
nullable: false,
defaultValue: 0);
}
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Year",
table: "SZUAbsolventenvereinHallOfFame");
migrationBuilder.DropColumn(
name: "Description",
table: "SZUAbsolventenvereinHallOfFame");
migrationBuilder.DropColumn(
name: "Image",
table: "SZUAbsolventenvereinHallOfFame");
migrationBuilder.DropColumn(
name: "Link",
table: "SZUAbsolventenvereinHallOfFame");
migrationBuilder.DropColumn(
name: "Status",
table: "SZUAbsolventenvereinHallOfFame");
migrationBuilder.DropColumn(
name: "UserId",
table: "SZUAbsolventenvereinHallOfFame");
}
}
}

View File

@@ -25,6 +25,12 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Migrations.EntityBuilders
HallOfFameId = AddAutoIncrementColumn(table,"HallOfFameId"); HallOfFameId = AddAutoIncrementColumn(table,"HallOfFameId");
ModuleId = AddIntegerColumn(table,"ModuleId"); ModuleId = AddIntegerColumn(table,"ModuleId");
Name = AddMaxStringColumn(table,"Name"); Name = AddMaxStringColumn(table,"Name");
Year = AddIntegerColumn(table,"Year");
Description = AddMaxStringColumn(table,"Description");
Image = AddMaxStringColumn(table,"Image");
Link = AddMaxStringColumn(table,"Link");
Status = AddStringColumn(table,"Status", 50);
UserId = AddIntegerColumn(table,"UserId");
AddAuditableColumns(table); AddAuditableColumns(table);
return this; return this;
} }
@@ -32,5 +38,12 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Migrations.EntityBuilders
public OperationBuilder<AddColumnOperation> HallOfFameId { get; set; } public OperationBuilder<AddColumnOperation> HallOfFameId { get; set; }
public OperationBuilder<AddColumnOperation> ModuleId { get; set; } public OperationBuilder<AddColumnOperation> ModuleId { get; set; }
public OperationBuilder<AddColumnOperation> Name { get; set; } public OperationBuilder<AddColumnOperation> Name { get; set; }
public OperationBuilder<AddColumnOperation> Year { get; set; }
public OperationBuilder<AddColumnOperation> Description { get; set; }
public OperationBuilder<AddColumnOperation> Image { get; set; }
public OperationBuilder<AddColumnOperation> Link { get; set; }
public OperationBuilder<AddColumnOperation> Status { get; set; }
public OperationBuilder<AddColumnOperation> UserId { get; set; }
} }
} }

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc> <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Version>1.0.0</Version> <Version>1.0.1</Version>
<Product>SZUAbsolventenverein.Module.HallOfFame</Product> <Product>SZUAbsolventenverein.Module.HallOfFame</Product>
<Authors>SZUAbsolventenverein</Authors> <Authors>SZUAbsolventenverein</Authors>
<Company>SZUAbsolventenverein</Company> <Company>SZUAbsolventenverein</Company>

View File

@@ -54,6 +54,20 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
} }
} }
public Task<Models.HallOfFame> GetHallOfFameByUserIdAsync(int UserId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
// Assuming Repository doesn't have specific method yet, using LINQ on GetHallOfFames
return Task.FromResult(_HallOfFameRepository.GetHallOfFames(ModuleId).FirstOrDefault(item => item.UserId == UserId));
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame GetByUserId Attempt {UserId} {ModuleId}", UserId, ModuleId);
return null;
}
}
public Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame) public Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame)
{ {
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, HallOfFame.ModuleId, PermissionNames.Edit)) if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, HallOfFame.ModuleId, PermissionNames.Edit))

View File

@@ -12,6 +12,14 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Models
public int HallOfFameId { get; set; } public int HallOfFameId { get; set; }
public int ModuleId { get; set; } public int ModuleId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int Year { get; set; }
public string Description { get; set; }
public string Image { get; set; }
public string Link { get; set; }
public string Status { get; set; } // "Draft" or "Published"
public int UserId { get; set; } // Owner
public string CreatedBy { get; set; } public string CreatedBy { get; set; }
public DateTime CreatedOn { get; set; } public DateTime CreatedOn { get; set; }

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<Version>1.0.0</Version> <Version>1.0.1</Version>
<Product>SZUAbsolventenverein.Module.HallOfFame</Product> <Product>SZUAbsolventenverein.Module.HallOfFame</Product>
<Authors>SZUAbsolventenverein</Authors> <Authors>SZUAbsolventenverein</Authors>
<Company>SZUAbsolventenverein</Company> <Company>SZUAbsolventenverein</Company>