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 DisableEnergyProviderCommand { public long ProviderId { get; set; } public DateTime? DisabledAt { get; set; } } public class DisableEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler { public Task HandleAsync(DisableEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken()) { return energyService.DisableEnergyProviderAsync(new DisableEnergyProviderCommandOptions { ProviderId = command.ProviderId, DisabledAt = command.DisabledAt, }, cancellationToken); } } public class DisableEnergyProviderCommandValidator : AbstractValidator { public DisableEnergyProviderCommandValidator(CHDbContext dbContext) { RuleFor(command => command.ProviderId) .NotEmpty() .SetValidator(new DbEntityExistValidator(dbContext)) .WithMessage("The provided provider Id is invalid."); } }