using NetinaCMS.Repository.Repositories.Base.Contracts;

namespace NetinaCMS.Repository.Handlers.BlogCategories;

public class CreateBlogCategoryCommandHandler : IRequestHandler<CreateBlogCategoryCommand,bool>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public CreateBlogCategoryCommandHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<bool> Handle(CreateBlogCategoryCommand request, CancellationToken cancellationToken)
    {
        var ent = BlogCategory.Create(request.Name, request.Description);
        _repositoryWrapper.SetRepository<BlogCategory>()
            .Add(ent);
        await _repositoryWrapper.SaveChangesAsync(cancellationToken);
        return true;
    }
}