Refactored DTO class and namespace names from Massdata* to MassData* in DbFirst.Contracts. Updated all relevant application files to use the correct DTO namespaces for Catalogs and MassData. Adjusted _Imports.razor to include new DTO namespaces and removed unused usings. These changes improve code consistency and reduce namespace-related errors.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using AutoMapper;
|
|
using DbFirst.Application.Repositories;
|
|
using DbFirst.Domain.Entities;
|
|
using MediatR;
|
|
using DbFirst.Contracts.Catalogs;
|
|
|
|
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);
|
|
}
|
|
}
|