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

38 lines
1.2 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 DisableEnergyProviderCommand
{
public long ProviderId { get; set; }
public DateTime? DisabledAt { get; set; }
}
public class DisableEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler<DisableEnergyProviderCommand>
{
public Task HandleAsync(DisableEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken())
{
return energyService.DisableEnergyProviderAsync(new DisableEnergyProviderCommandOptions
{
ProviderId = command.ProviderId,
DisabledAt = command.DisabledAt,
}, cancellationToken);
}
}
public class DisableEnergyProviderCommandValidator : AbstractValidator<DisableEnergyProviderCommand>
{
public DisableEnergyProviderCommandValidator(CHDbContext dbContext)
{
RuleFor(command => command.ProviderId)
.NotEmpty()
.SetValidator(new DbEntityExistValidator<EnergyProvider,long>(dbContext))
.WithMessage("The provided provider Id is invalid.");
}
}