24 lines
943 B
C#
24 lines
943 B
C#
using NetinaShop.Domain.Entities.Brands;
|
|
|
|
namespace NetinaShop.Repository.Handlers.Brands;
|
|
|
|
public class CreateBrandCommandHandler : IRequestHandler<CreateBrandCommand , BrandSDto>
|
|
{
|
|
private IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public CreateBrandCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<BrandSDto> Handle(CreateBrandCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var ent = Brand.Create(request.Name, request.Description, request.HasSpecialPage, request.PageUrl);
|
|
foreach (var file in request.Files)
|
|
{
|
|
ent.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
|
}
|
|
_repositoryWrapper.SetRepository<Brand>().Add(ent);
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
return ent.AdaptToSDto();
|
|
}
|
|
} |