24 lines
950 B
C#
24 lines
950 B
C#
using Netina.Domain.Entities.Brands;
|
|
|
|
namespace Netina.Repository.Handlers.Brands;
|
|
|
|
public class CreateBrandCommandHandler : IRequestHandler<CreateBrandCommand , Guid>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public CreateBrandCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<Guid> Handle(CreateBrandCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var ent = Brand.Create(request.PersianName,request.EnglishName, 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.Id;
|
|
}
|
|
} |