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.
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using AutoMapper;
|
|
using DbFirst.Domain.Entities;
|
|
using DbFirst.Domain.Repositories;
|
|
using DbFirst.Domain;
|
|
using MediatR;
|
|
|
|
namespace DbFirst.Application.Catalogs.Commands;
|
|
|
|
public class UpdateCatalogHandler : IRequestHandler<UpdateCatalogCommand, CatalogReadDto?>
|
|
{
|
|
private readonly ICatalogRepository _repository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public UpdateCatalogHandler(ICatalogRepository repository, IMapper mapper)
|
|
{
|
|
_repository = repository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<CatalogReadDto?> Handle(UpdateCatalogCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var existing = await _repository.GetByIdAsync(request.Id, cancellationToken);
|
|
if (existing == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var entity = _mapper.Map<VwmyCatalog>(request.Dto);
|
|
entity.Guid = request.Id;
|
|
entity.CatTitle = existing.CatTitle;
|
|
entity.AddedWho = existing.AddedWho;
|
|
entity.AddedWhen = existing.AddedWhen;
|
|
entity.ChangedWho = "system";
|
|
entity.ChangedWhen = DateTime.UtcNow;
|
|
|
|
var procedure = request.Dto.UpdateProcedure;
|
|
var updated = await _repository.UpdateAsync(request.Id, entity, procedure, cancellationToken);
|
|
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
|
|
}
|
|
}
|