- 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.
201 lines
8.6 KiB
Plaintext
201 lines
8.6 KiB
Plaintext
@using Oqtane.Modules.Controls
|
|
@using SZUAbsolventenverein.Module.HallOfFame.Services
|
|
@using SZUAbsolventenverein.Module.HallOfFame.Models
|
|
|
|
@namespace SZUAbsolventenverein.Module.HallOfFame
|
|
@inherits ModuleBase
|
|
@inject IHallOfFameService HallOfFameService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IStringLocalizer<Edit> Localizer
|
|
|
|
<form @ref="form" class="@(validated ? " was-validated" : "needs-validation" )" novalidate>
|
|
<div class="container">
|
|
<div class="row mb-3 align-items-center">
|
|
<Label Class="col-sm-3 col-form-label" For="name" HelpText="Gib deinen Namen ein" ResourceKey="Name">Name: </Label>
|
|
<div class="col-sm-9">
|
|
<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 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 />
|
|
@if (PageState.Action == "Edit")
|
|
{
|
|
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
|
|
}
|
|
</form>
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; // Logic handles checking user own entry
|
|
|
|
public override string Actions => "Add,Edit";
|
|
|
|
public override string Title => "Hall of Fame Eintrag verwalten";
|
|
|
|
public override List<Resource> Resources => new List<Resource>()
|
|
{
|
|
new Stylesheet("_content/SZUAbsolventenverein.Module.HallOfFame/Module.css")
|
|
};
|
|
|
|
private ElementReference form;
|
|
private bool validated = false;
|
|
|
|
private int _id;
|
|
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 DateTime _createdon;
|
|
private string _modifiedby;
|
|
private DateTime _modifiedon;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
if (PageState.Action == "Edit")
|
|
{
|
|
_id = Int32.Parse(PageState.QueryString["id"]);
|
|
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
|
|
|
|
// Security check: only allow editing own entry
|
|
if (HallOfFame != null)
|
|
{
|
|
if (HallOfFame.UserId != PageState.User.UserId)
|
|
{
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
return;
|
|
}
|
|
|
|
_name = HallOfFame.Name;
|
|
_year = HallOfFame.Year;
|
|
_description = HallOfFame.Description;
|
|
_image = HallOfFame.Image;
|
|
_link = HallOfFame.Link;
|
|
_status = HallOfFame.Status;
|
|
|
|
_createdby = HallOfFame.CreatedBy;
|
|
_createdon = HallOfFame.CreatedOn;
|
|
_modifiedby = HallOfFame.ModifiedBy;
|
|
_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)
|
|
{
|
|
await logger.LogError(ex, "Error Loading HallOfFame {HallOfFameId} {Error}", _id, ex.Message);
|
|
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task Save(string status)
|
|
{
|
|
try
|
|
{
|
|
validated = true;
|
|
var interop = new Oqtane.UI.Interop(JSRuntime);
|
|
if (await interop.FormValid(form))
|
|
{
|
|
_status = status;
|
|
|
|
if (PageState.Action == "Add")
|
|
{
|
|
HallOfFame HallOfFame = new HallOfFame();
|
|
HallOfFame.ModuleId = ModuleState.ModuleId;
|
|
HallOfFame.UserId = PageState.User.UserId; // Set Owner
|
|
HallOfFame.Name = _name;
|
|
HallOfFame.Year = _year;
|
|
HallOfFame.Description = _description;
|
|
HallOfFame.Image = _image;
|
|
HallOfFame.Link = _link;
|
|
HallOfFame.Status = _status;
|
|
|
|
HallOfFame = await HallOfFameService.AddHallOfFameAsync(HallOfFame);
|
|
await logger.LogInformation("HallOfFame Added {HallOfFame}", HallOfFame);
|
|
}
|
|
else
|
|
{
|
|
HallOfFame HallOfFame = await HallOfFameService.GetHallOfFameAsync(_id, ModuleState.ModuleId);
|
|
// Ensure we don't overwrite with invalid user logic, though server checks too
|
|
if (HallOfFame.UserId == PageState.User.UserId)
|
|
{
|
|
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());
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.SaveValidation"], MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving HallOfFame {Error}", ex.Message);
|
|
AddModuleMessage(Localizer["Message.SaveError"], MessageType.Error);
|
|
}
|
|
}
|
|
}
|