CS2-5: Добавлена проверка данных на наличие при добавлении в архив

This commit is contained in:
KharchenkoVV 2021-05-13 12:24:21 +05:00
parent 7df66b314e
commit 0be4847f58

View File

@ -68,19 +68,32 @@ namespace AsbCloudInfrastructure.Services
public void UpdateData(string uid, IEnumerable<DataSaubBaseDto> 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<DataSaubBase>(item);
dataSaub.IdTelemetry = telemetryId;
db.DataSaubBases.Add(dataSaub);
}
db.SaveChanges();
db.DataSaubBases.RemoveRange(oldDataSaubBase);
}
foreach (var item in dtos)
{
var dataSaub = mapper.Map<DataSaubBase>(item);
dataSaub.IdTelemetry = telemetryId;
db.DataSaubBases.Add(dataSaub);
}
db.SaveChanges();
}
}