using CH.CQRS.Service.Energy; using CH.Dal; using CH.Dal.DbEntity; using CH.Dal.Validators; using FluentValidation; using OpenHarbor.CQRS.Abstractions; namespace CH.CQRS.Command.Energy; public class EnableEnergyRateCommand { public long RateId { get; set; } } public class EnableEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler { public Task HandleAsync(EnableEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken()) { return energyService.EnableEnergyRateAsync(new EnableEnergyRateCommandOptions { RateId = command.RateId }, cancellationToken); } } public class EnableEnergyRateCommandValidator : AbstractValidator { public EnableEnergyRateCommandValidator(CHDbContext dbContext) { RuleFor(command => command.RateId) .NotEmpty() .SetValidator(new DbEntityExistValidator(dbContext)) .WithMessage("The provided Rate Id is invalid."); } }