Restrict CatTitle editing based on UpdateProcedure

Enforce business rules for catalog title changes: only allow CatTitle to be edited when UpdateProcedure permits, with checks in the API, service, handler, and UI. This ensures consistent validation and user experience across backend and frontend.
This commit is contained in:
OlgunR
2026-01-19 14:44:55 +01:00
parent 26f783e835
commit 0af0c4589d
4 changed files with 8 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
using DbFirst.Application.Catalogs; using DbFirst.Application.Catalogs;
using DbFirst.Application.Catalogs.Commands; using DbFirst.Application.Catalogs.Commands;
using DbFirst.Application.Catalogs.Queries; using DbFirst.Application.Catalogs.Queries;
using DbFirst.Domain;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -54,7 +55,8 @@ public class CatalogsController : ControllerBase
{ {
return NotFound(); return NotFound();
} }
if (!string.Equals(current.CatTitle, dto.CatTitle, StringComparison.OrdinalIgnoreCase)) if (dto.UpdateProcedure == CatalogUpdateProcedure.Update &&
!string.Equals(current.CatTitle, dto.CatTitle, StringComparison.OrdinalIgnoreCase))
{ {
return BadRequest("Titel kann nicht geändert werden."); return BadRequest("Titel kann nicht geändert werden.");
} }

View File

@@ -60,7 +60,7 @@ public class CatalogService : ICatalogService
var entity = _mapper.Map<VwmyCatalog>(dto); var entity = _mapper.Map<VwmyCatalog>(dto);
entity.Guid = id; entity.Guid = id;
entity.CatTitle = existing.CatTitle; entity.CatTitle = dto.UpdateProcedure == CatalogUpdateProcedure.Update ? existing.CatTitle : dto.CatTitle;
entity.AddedWho = existing.AddedWho; entity.AddedWho = existing.AddedWho;
entity.AddedWhen = existing.AddedWhen; entity.AddedWhen = existing.AddedWhen;
entity.ChangedWho = "system"; entity.ChangedWho = "system";

View File

@@ -27,7 +27,9 @@ public class UpdateCatalogHandler : IRequestHandler<UpdateCatalogCommand, Catalo
var entity = _mapper.Map<VwmyCatalog>(request.Dto); var entity = _mapper.Map<VwmyCatalog>(request.Dto);
entity.Guid = request.Id; entity.Guid = request.Id;
entity.CatTitle = existing.CatTitle; entity.CatTitle = request.Dto.UpdateProcedure == CatalogUpdateProcedure.Update
? existing.CatTitle
: request.Dto.CatTitle;
entity.AddedWho = existing.AddedWho; entity.AddedWho = existing.AddedWho;
entity.AddedWhen = existing.AddedWhen; entity.AddedWhen = existing.AddedWhen;
entity.ChangedWho = "system"; entity.ChangedWho = "system";

View File

@@ -24,7 +24,7 @@ else if (!string.IsNullOrWhiteSpace(infoMessage))
<div class="row g-3"> <div class="row g-3">
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label">Titel</label> <label class="form-label">Titel</label>
<InputText class="form-control" @bind-Value="formModel.CatTitle" disabled="@isEditing" /> <InputText class="form-control" @bind-Value="formModel.CatTitle" disabled="@(isEditing && formModel.UpdateProcedure == 0)" />
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label">Kennung</label> <label class="form-label">Kennung</label>