2025-01-10 15:59:51 -05:00
|
|
|
using CH.CQRS.Service.Energy;
|
2025-01-13 19:19:03 -05:00
|
|
|
using CH.Dal;
|
|
|
|
using CH.Dal.DbEntity;
|
|
|
|
using CH.Dal.Validators;
|
|
|
|
using FluentValidation;
|
2025-01-10 15:59:51 -05:00
|
|
|
using OpenHarbor.CQRS.Abstractions;
|
|
|
|
|
|
|
|
namespace CH.CQRS.Command.Energy;
|
|
|
|
|
|
|
|
public class EnableEnergyRateCommand
|
|
|
|
{
|
|
|
|
public long RateId { get; set; }
|
|
|
|
}
|
|
|
|
public class EnableEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler<EnableEnergyRateCommand>
|
|
|
|
{
|
|
|
|
public Task HandleAsync(EnableEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken())
|
|
|
|
{
|
|
|
|
return energyService.EnableEnergyRateAsync(new EnableEnergyRateCommandOptions
|
|
|
|
{
|
|
|
|
RateId = command.RateId
|
|
|
|
}, cancellationToken);
|
|
|
|
}
|
2025-01-13 19:19:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public class EnableEnergyRateCommandValidator : AbstractValidator<EnableEnergyRateCommand>
|
|
|
|
{
|
|
|
|
public EnableEnergyRateCommandValidator(CHDbContext dbContext)
|
|
|
|
{
|
|
|
|
RuleFor(command => command.RateId)
|
|
|
|
.NotEmpty()
|
|
|
|
.SetValidator(new DbEntityExistValidator<EnergyRate,long>(dbContext))
|
|
|
|
.WithMessage("The provided Rate Id is invalid.");
|
|
|
|
}
|
2025-01-10 15:59:51 -05:00
|
|
|
}
|