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

32 lines
962 B
C#
Raw Normal View History

using CH.CQRS.Service.Energy;
using CH.CQRS.Service.Energy.Options;
using FluentValidation;
using OpenHarbor.CQRS.Abstractions;
namespace CH.CQRS.Command.Energy;
public class UpdateEnergyProviderCommand
{
public long ProviderId { get; set; }
public required string Name { get; set; }
}
public class UpdateEnergyProviderCommandHandler(EnergyService energyService) : ICommandHandler<UpdateEnergyProviderCommand>
{
public Task HandleAsync(UpdateEnergyProviderCommand command, CancellationToken cancellationToken = new CancellationToken())
{
return energyService.UpdateEnergyProviderAsync(new UpdateEnergyProviderCommandOptions
{
ProviderId = command.ProviderId,
Name = command.Name
},cancellationToken);
}
}
public class UpdateEnergyProviderCommandValidator : AbstractValidator<UpdateEnergyProviderCommand>
{
public UpdateEnergyProviderCommandValidator()
{
RuleFor(command => command.ProviderId)
.NotEmpty();
}
}