Fix TelemetryWirelineRunOut. AddOrUpdateAsync issue

This commit is contained in:
ngfrolov 2023-01-19 12:28:38 +05:00
parent f7654a95b6
commit 4dced662e1
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -34,15 +34,11 @@ namespace AsbCloudInfrastructure.Repository
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
var timezoneOffset = telemetryService.GetTimezone(idTelemetry).Hours;
var entity = Convert(idTelemetry, dto, timezoneOffset);
var updatingItem = context.TelemetryWirelineRunOut
.Where(x => x.IdTelemetry == idTelemetry)
.FirstOrDefault();
if (updatingItem is null)
context.TelemetryWirelineRunOut.Add(entity);
else
if (await context.TelemetryWirelineRunOut.AnyAsync(w => w.IdTelemetry == idTelemetry, token))
context.TelemetryWirelineRunOut.Update(entity);
else
context.TelemetryWirelineRunOut.Add(entity);
return await context.SaveChangesAsync(token);
}