Refactored IRepository<T> and ICatalogRepository to reside in the DbFirst.Application layer instead of Domain. Updated namespaces, using statements, and all references in services and handlers. Adjusted csproj dependencies to reflect the new structure. Updated comments to clarify Clean Architecture rationale and improved separation of concerns.
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using AutoMapper;
|
|
using DbFirst.Application.Repositories;
|
|
using DbFirst.Domain.Entities;
|
|
using MediatR;
|
|
|
|
namespace DbFirst.Application.Catalogs.Commands;
|
|
|
|
public class CreateCatalogHandler : IRequestHandler<CreateCatalogCommand, CatalogReadDto?>
|
|
{
|
|
private readonly ICatalogRepository _repository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public CreateCatalogHandler(ICatalogRepository repository, IMapper mapper)
|
|
{
|
|
_repository = repository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<CatalogReadDto?> Handle(CreateCatalogCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var existing = await _repository.GetByTitleAsync(request.Dto.CatTitle, cancellationToken);
|
|
if (existing != null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var entity = _mapper.Map<VwmyCatalog>(request.Dto);
|
|
entity.AddedWho = "system";
|
|
entity.AddedWhen = DateTime.UtcNow;
|
|
entity.ChangedWho = "system";
|
|
entity.ChangedWhen = DateTime.UtcNow;
|
|
|
|
var created = await _repository.InsertAsync(entity, cancellationToken);
|
|
return _mapper.Map<CatalogReadDto>(created);
|
|
}
|
|
}
|