From f1b1b010125dfaff35bed99a4084b33f512e3597 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Mon, 17 Apr 2023 18:10:25 +0500 Subject: [PATCH] fix convert --- .../Repository/GtrWitsRepository.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs index a13bbac0..2bd79b87 100644 --- a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs +++ b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs @@ -96,17 +96,17 @@ namespace AsbCloudInfrastructure.Repository var jsonValue = item.Value; if(jsonValue.value is string valueString) { - var entity = ConvertToEntity(dto, valueString, item.Key, timezoneHours); + var entity = ConvertToEntity(dto, valueString, timezoneHours); db.WitsItemString.Add(entity.Adapt()); } if (jsonValue.value is float valueFloat) { - var entity = ConvertToEntity(dto, valueFloat, item.Key, timezoneHours); + var entity = ConvertToEntity(dto, valueFloat, timezoneHours); db.WitsItemFloat.Add(entity.Adapt()); } if (jsonValue.value is int valueInt) { - var entity = ConvertToEntity(dto, valueInt, item.Key, timezoneHours); + var entity = ConvertToEntity(dto, valueInt, timezoneHours); db.WitsItemInt.Add(entity.Adapt()); } } @@ -150,17 +150,12 @@ namespace AsbCloudInfrastructure.Repository }); return items; } - private static WitsItemBase ConvertToEntity(WitsRecordDto record, Tvalue value, int idItems, double timezoneHours) + private static WitsItemBase ConvertToEntity(WitsRecordDto record, Tvalue value, double timezoneHours) where Tvalue: notnull { - var entity = new WitsItemBase - { - IdTelemetry = record.IdTelemetry, - DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours), - IdRecord = record.Id, - IdItem = idItems, - Value = value, - }; + var entity = record.Adapt>(); + entity.DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours); + entity.Value = value; return entity; }