From 0be4847f58f1e5d2e877292c424735032d052240 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Thu, 13 May 2021 12:24:21 +0500 Subject: [PATCH] =?UTF-8?q?CS2-5:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B2=20=D0=B0=D1=80=D1=85=D0=B8=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DataService.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index 089dcf9e..2cfb9d08 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -68,19 +68,32 @@ namespace AsbCloudInfrastructure.Services public void UpdateData(string uid, IEnumerable dtos) { + if (dtos == default || dtos.Count() <= 0) + return; + var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid); + var dtoMinDate = dtos.Min(d => d.Date); + var dtoMaxDate = dtos.Max(d => d.Date); - if ((dtos != default) && (dtos.Count() > 0)) + var oldDataSaubBase = (from d in db.DataSaubBases + where d.IdTelemetry == telemetryId + && d.Date > dtoMinDate + && d.Date < dtoMaxDate + select d).ToList(); + + if (oldDataSaubBase.Any()) { - foreach (var item in dtos) - { - var dataSaub = mapper.Map(item); - dataSaub.IdTelemetry = telemetryId; - db.DataSaubBases.Add(dataSaub); - } - - db.SaveChanges(); + db.DataSaubBases.RemoveRange(oldDataSaubBase); } + + foreach (var item in dtos) + { + var dataSaub = mapper.Map(item); + dataSaub.IdTelemetry = telemetryId; + db.DataSaubBases.Add(dataSaub); + } + + db.SaveChanges(); } }