fix convert

This commit is contained in:
eugeniy_ivanov 2023-04-17 18:10:25 +05:00
parent 4df94466f0
commit f1b1b01012

View File

@ -96,17 +96,17 @@ namespace AsbCloudInfrastructure.Repository
var jsonValue = item.Value; var jsonValue = item.Value;
if(jsonValue.value is string valueString) 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<WitsItemString>()); db.WitsItemString.Add(entity.Adapt<WitsItemString>());
} }
if (jsonValue.value is float valueFloat) 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<WitsItemFloat>()); db.WitsItemFloat.Add(entity.Adapt<WitsItemFloat>());
} }
if (jsonValue.value is int valueInt) 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<WitsItemInt>()); db.WitsItemInt.Add(entity.Adapt<WitsItemInt>());
} }
} }
@ -150,17 +150,12 @@ namespace AsbCloudInfrastructure.Repository
}); });
return items; return items;
} }
private static WitsItemBase<Tvalue> ConvertToEntity<Tvalue>(WitsRecordDto record, Tvalue value, int idItems, double timezoneHours) private static WitsItemBase<Tvalue> ConvertToEntity<Tvalue>(WitsRecordDto record, Tvalue value, double timezoneHours)
where Tvalue: notnull where Tvalue: notnull
{ {
var entity = new WitsItemBase<Tvalue> var entity = record.Adapt<WitsItemBase<Tvalue>>();
{ entity.DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours);
IdTelemetry = record.IdTelemetry, entity.Value = value;
DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours),
IdRecord = record.Id,
IdItem = idItems,
Value = value,
};
return entity; return entity;
} }