From 0af0c4589dd9f5d700b3ecc7056ecbd737c1c3f4 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 19 Jan 2026 14:44:55 +0100 Subject: [PATCH] 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. --- DbFirst.API/Controllers/CatalogsController.cs | 4 +++- DbFirst.Application/Catalogs/CatalogService.cs | 2 +- DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs | 4 +++- DbFirst.BlazorWasm/Pages/Catalogs.razor | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/DbFirst.API/Controllers/CatalogsController.cs b/DbFirst.API/Controllers/CatalogsController.cs index 103d386..254b39d 100644 --- a/DbFirst.API/Controllers/CatalogsController.cs +++ b/DbFirst.API/Controllers/CatalogsController.cs @@ -1,6 +1,7 @@ using DbFirst.Application.Catalogs; using DbFirst.Application.Catalogs.Commands; using DbFirst.Application.Catalogs.Queries; +using DbFirst.Domain; using MediatR; using Microsoft.AspNetCore.Mvc; @@ -54,7 +55,8 @@ public class CatalogsController : ControllerBase { 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."); } diff --git a/DbFirst.Application/Catalogs/CatalogService.cs b/DbFirst.Application/Catalogs/CatalogService.cs index dbf5904..5d0d403 100644 --- a/DbFirst.Application/Catalogs/CatalogService.cs +++ b/DbFirst.Application/Catalogs/CatalogService.cs @@ -60,7 +60,7 @@ public class CatalogService : ICatalogService var entity = _mapper.Map(dto); entity.Guid = id; - entity.CatTitle = existing.CatTitle; + entity.CatTitle = dto.UpdateProcedure == CatalogUpdateProcedure.Update ? existing.CatTitle : dto.CatTitle; entity.AddedWho = existing.AddedWho; entity.AddedWhen = existing.AddedWhen; entity.ChangedWho = "system"; diff --git a/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs b/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs index 016e438..e236981 100644 --- a/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs +++ b/DbFirst.Application/Catalogs/Commands/UpdateCatalogHandler.cs @@ -27,7 +27,9 @@ public class UpdateCatalogHandler : IRequestHandler(request.Dto); 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.AddedWhen = existing.AddedWhen; entity.ChangedWho = "system"; diff --git a/DbFirst.BlazorWasm/Pages/Catalogs.razor b/DbFirst.BlazorWasm/Pages/Catalogs.razor index 2c2ef09..5d83a3a 100644 --- a/DbFirst.BlazorWasm/Pages/Catalogs.razor +++ b/DbFirst.BlazorWasm/Pages/Catalogs.razor @@ -24,7 +24,7 @@ else if (!string.IsNullOrWhiteSpace(infoMessage))
- +