From 0ba2e45b38917608965960078177b8e656fbc81b Mon Sep 17 00:00:00 2001 From: DavidGudEnough Date: Wed, 22 Jan 2025 18:11:25 -0500 Subject: [PATCH] add currency in update command --- CH.CQRS/Command/Energy/UpdateEnergyRateCommand.cs | 5 ++++- CH.CQRS/Service/Energy/EnergyService.cs | 3 ++- .../Service/Energy/Options/UpdateEnergyRateCommandOptions.cs | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CH.CQRS/Command/Energy/UpdateEnergyRateCommand.cs b/CH.CQRS/Command/Energy/UpdateEnergyRateCommand.cs index 59ef1f9..96890f7 100644 --- a/CH.CQRS/Command/Energy/UpdateEnergyRateCommand.cs +++ b/CH.CQRS/Command/Energy/UpdateEnergyRateCommand.cs @@ -4,6 +4,7 @@ using CH.CQRS.Service.Energy.Options; using CH.Dal; using CH.Dal.DbEntity; using CH.Dal.Validators; +using CH.Enum; using FluentValidation; using Microsoft.EntityFrameworkCore; using OpenHarbor.CQRS.Abstractions; @@ -16,6 +17,7 @@ public class UpdateEnergyRateCommand public string? Name { get; set; } public DateTime? StartedAt { get; set; } public decimal? Rate { get; set; } + public Currency Currency { get; set; } } public class UpdateEnergyRateCommandHandler(EnergyService energyService) : ICommandHandler { @@ -26,7 +28,8 @@ public class UpdateEnergyRateCommandHandler(EnergyService energyService) : IComm RateId = command.RateId, Name = command.Name, StartedAt = command.StartedAt, - Rate = command.Rate + Rate = command.Rate, + Currency = command.Currency }, cancellationToken); } } diff --git a/CH.CQRS/Service/Energy/EnergyService.cs b/CH.CQRS/Service/Energy/EnergyService.cs index 0c5568d..339733e 100644 --- a/CH.CQRS/Service/Energy/EnergyService.cs +++ b/CH.CQRS/Service/Energy/EnergyService.cs @@ -83,10 +83,11 @@ public class EnergyService(CHDbContext dbContext) if (options.Rate.HasValue) energyRate.Rate = options.Rate.Value; - + if (false == string.IsNullOrWhiteSpace(options.Name)) energyRate.Name = options.Name; + energyRate.Currency = options.Currency; energyRate.UpdatedAt = DateTime.UtcNow; } public async Task UpdateEnergyRateAsync(UpdateEnergyRateCommandOptions options, CancellationToken cancellationToken) diff --git a/CH.CQRS/Service/Energy/Options/UpdateEnergyRateCommandOptions.cs b/CH.CQRS/Service/Energy/Options/UpdateEnergyRateCommandOptions.cs index 5e6469f..e8f3dfd 100644 --- a/CH.CQRS/Service/Energy/Options/UpdateEnergyRateCommandOptions.cs +++ b/CH.CQRS/Service/Energy/Options/UpdateEnergyRateCommandOptions.cs @@ -1,3 +1,5 @@ +using CH.Enum; + namespace CH.CQRS.Service.Energy.Options; public class UpdateEnergyRateCommandOptions @@ -6,4 +8,5 @@ public class UpdateEnergyRateCommandOptions public DateTime? StartedAt { get; set; } public decimal? Rate { get; set; } public string? Name { get; set; } + public Currency Currency { get; set; } } \ No newline at end of file