Move catalog title update validation to handler
Validation preventing CatTitle changes during updates is now enforced in UpdateCatalogHandler instead of the controller. The handler throws an exception if a title change is attempted. Also, streamlined UpdateProcedure handling and removed redundant CatTitle mapping logic.
This commit is contained in:
@@ -25,18 +25,20 @@ public class UpdateCatalogHandler : IRequestHandler<UpdateCatalogCommand, Catalo
|
||||
return null;
|
||||
}
|
||||
|
||||
if (request.Dto.UpdateProcedure == CatalogUpdateProcedure.Update &&
|
||||
!string.Equals(existing.CatTitle, request.Dto.CatTitle, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException("Titel kann nicht geändert werden.");
|
||||
}
|
||||
|
||||
var entity = _mapper.Map<VwmyCatalog>(request.Dto);
|
||||
entity.Guid = request.Id;
|
||||
entity.CatTitle = request.Dto.UpdateProcedure == CatalogUpdateProcedure.Update
|
||||
? existing.CatTitle
|
||||
: request.Dto.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);
|
||||
var updated = await _repository.UpdateAsync(request.Id, entity, request.Dto.UpdateProcedure, cancellationToken);
|
||||
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user