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 DisableEnergyRateCommand { public long RateId { get; set; } public DateTime? DisabledAt { get; set; } } public class DisableEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler { public Task HandleAsync(DisableEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken()) { return energyService.DisableEnergyRateAsync(new DisableEnergyRateCommandOptions { RateId = command.RateId, DisabledAt = command.DisabledAt }, cancellationToken); } } public class DisableEnergyRateCommandValidator : AbstractValidator { public DisableEnergyRateCommandValidator(CHDbContext dbContext) { RuleFor(command => command.RateId) .NotEmpty() .SetValidator(new DbEntityExistValidator(dbContext)) .WithMessage("The provided Rate Id is invalid."); } }