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

37 lines
1.1 KiB
C#

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<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(CHDbContext dbContext)
{
RuleFor(command => command.RateId)
.NotEmpty()
.SetValidator(new DbEntityExistValidator<EnergyRate,long>(dbContext))
.WithMessage("The provided Rate Id is invalid.");
}
}