using CH.CQRS.Service.Energy; using CH.CQRS.Service.Energy.Options; using CH.Dal; using CH.Dal.DbEntity; using CH.Dal.Validators; using FluentValidation; using OpenHarbor.CQRS.Abstractions; namespace CH.CQRS.Command.Energy; public class EnableEnergyProviderCommand { public long ProviderId { get; set; } } public class EnableEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler { public Task HandleAsync(EnableEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken()) { return energyService.EnableEnergyProviderAsync(new EnableEnergyProviderCommandOptions() { ProviderId = command.ProviderId }, cancellationToken); } } public class EnableEnergyProviderCommandValidator : AbstractValidator { public EnableEnergyProviderCommandValidator(CHDbContext dbContext) { RuleFor(command => command.ProviderId) .NotEmpty() .SetValidator(new DbEntityExistValidator(dbContext)) .WithMessage("The provided provider Id is invalid."); } }