2024-04-23 12:09:32 +03:30
|
|
|
|
using Netina.Domain.Entities.Brands;
|
2024-01-13 13:05:37 +03:30
|
|
|
|
|
2024-04-16 20:01:34 +03:30
|
|
|
|
namespace Netina.Repository.Handlers.Brands;
|
2024-01-13 13:05:37 +03:30
|
|
|
|
|
|
|
|
|
|
public class CreateBrandCommandHandler : IRequestHandler<CreateBrandCommand , BrandSDto>
|
|
|
|
|
|
{
|
2024-02-22 20:34:51 +03:30
|
|
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
2024-01-13 13:05:37 +03:30
|
|
|
|
|
|
|
|
|
|
public CreateBrandCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
|
|
|
|
{
|
|
|
|
|
|
_repositoryWrapper = repositoryWrapper;
|
|
|
|
|
|
}
|
|
|
|
|
|
public async Task<BrandSDto> Handle(CreateBrandCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-02-22 20:34:51 +03:30
|
|
|
|
var ent = Brand.Create(request.PersianName,request.EnglishName, request.Description, request.HasSpecialPage, request.PageUrl);
|
2024-01-13 13:05:37 +03:30
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|