Support selecting update procedure for catalog updates

Added CatalogUpdateProcedure enum to domain. CatalogWriteDto now includes UpdateProcedure property in both application and BlazorWasm layers. Catalogs.razor form allows users to choose between PRTBMY_CATALOG_UPDATE and PRTBMY_CATALOG_SAVE when editing. Repository, service, and handler layers updated to pass and use the selected procedure. Default remains Update. Updated comments and TODOs for clarity and future refactoring.
This commit is contained in:
OlgunR
2026-01-19 11:10:19 +01:00
parent 45e5327148
commit 4fbcd0dc11
9 changed files with 43 additions and 46 deletions

View File

@@ -1,27 +1,14 @@
using AutoMapper;
using DbFirst.Domain.Repositories;
using DbFirst.Domain.Entities;
using DbFirst.Domain;
namespace DbFirst.Application.Catalogs;
//TODO: create generic service to reduce code duplication
/* Copilot's Response:
A generic CRUD base service adds little value in your case:
Pros:
• Less boilerplate for simple entities without special logic.
• Uniform CRUD signatures.
Cons/Practical here:
• Domain logic differs per entity(unique title check, setting audit fields, forbidding title changes, stored procs with output GUID).
• Generic services tend to be diluted by virtual methods/hooks for special cases—ending up with per-entity overrides and little real gain.
• With stored procedures and output parameters, the pattern doesnt fit cleanly because operations arent symmetric (separate procs for insert/update/delete).
Conclusion: For this solution a generic service would be more overhead than benefit. If you later have multiple very similar entities without special logic,
you could consider a lightweight generic interface/base; for now, the specialized service implementation is cleaner. */
//TODO (TR): kod tekrar?n? azaltmak için generic bir servis/basit CRUD altyap?s? ekleyin
//TODO: implement CQRS pattern with MediatR
//TODO (TR): CQRS desenini MediatR ile uygulay?n
public class CatalogService : ICatalogService
{
private readonly ICatalogRepository _repository;
@@ -79,7 +66,8 @@ public class CatalogService : ICatalogService
entity.ChangedWho = "system";
entity.ChangedWhen = DateTime.UtcNow;
var updated = await _repository.UpdateAsync(id, entity, cancellationToken);
var procedure = dto.UpdateProcedure;
var updated = await _repository.UpdateAsync(id, entity, procedure, cancellationToken);
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
}

View File

@@ -1,7 +1,10 @@
using DbFirst.Domain;
namespace DbFirst.Application.Catalogs;
public class CatalogWriteDto
{
public string CatTitle { get; set; } = null!;
public string CatString { get; set; } = null!;
public CatalogUpdateProcedure UpdateProcedure { get; set; } = CatalogUpdateProcedure.Update;
}

View File

@@ -1,6 +1,7 @@
using AutoMapper;
using DbFirst.Domain.Entities;
using DbFirst.Domain.Repositories;
using DbFirst.Domain;
using MediatR;
namespace DbFirst.Application.Catalogs.Commands;
@@ -32,7 +33,8 @@ public class UpdateCatalogHandler : IRequestHandler<UpdateCatalogCommand, Catalo
entity.ChangedWho = "system";
entity.ChangedWhen = DateTime.UtcNow;
var updated = await _repository.UpdateAsync(request.Id, entity, cancellationToken);
var procedure = request.Dto.UpdateProcedure;
var updated = await _repository.UpdateAsync(request.Id, entity, procedure, cancellationToken);
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
}
}