39 lines
1.2 KiB
C#
39 lines
1.2 KiB
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 CreateEnergyRateCommand
|
|
{
|
|
public long ProviderId { get; set; }
|
|
public required string Name { get; set; }
|
|
public decimal Price { get; set; }
|
|
public required string? Currency { get; set; }
|
|
public bool Active { get; set; }
|
|
}
|
|
public class CreateEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler<CreateEnergyRateCommand>
|
|
{
|
|
public Task HandleAsync(CreateEnergyRateCommand command, CancellationToken cancellationToken = new CancellationToken())
|
|
{
|
|
return energyService.CreateEnergyRateAsync(new CreateEnergyRateCommandOptions
|
|
{
|
|
ProviderId = command.ProviderId,
|
|
Name = command.Name,
|
|
Price = command.Price,
|
|
Currency = command.Currency,
|
|
Active = command.Active
|
|
},cancellationToken);
|
|
}
|
|
}
|
|
|
|
public class CreateEnergyRateCommandValidator : AbstractValidator<CreateEnergyRateCommand>
|
|
{
|
|
public CreateEnergyRateCommandValidator()
|
|
{
|
|
RuleFor(command => command.Price).GreaterThanOrEqualTo(0);
|
|
RuleFor(command => command.ProviderId)
|
|
.NotEmpty();
|
|
}
|
|
} |