constellation-api/CH.CQRS/Command/Energy/DisableEnergyRateCommand.cs

32 lines
932 B
C#

using CH.CQRS.Service.Energy;
using CH.CQRS.Service.Energy.Options;
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<DisableEnergyRateCommand>
{
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<DisableEnergyRateCommand>
{
public DisableEnergyRateCommandValidator()
{
RuleFor(command => command.RateId)
.NotEmpty();
}
}