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;
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>());
}
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>());
}
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>());
}
}
@ -150,17 +150,12 @@ namespace AsbCloudInfrastructure.Repository
});
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
{
var entity = new WitsItemBase<Tvalue>
{
IdTelemetry = record.IdTelemetry,
DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours),
IdRecord = record.Id,
IdItem = idItems,
Value = value,
};
var entity = record.Adapt<WitsItemBase<Tvalue>>();
entity.DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours);
entity.Value = value;
return entity;
}