forked from ddrilling/AsbCloudServer
CS2-5: Добавлена проверка данных на наличие при добавлении в архив
This commit is contained in:
parent
7df66b314e
commit
0be4847f58
@ -68,19 +68,32 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public void UpdateData(string uid, IEnumerable<DataSaubBaseDto> dtos)
|
public void UpdateData(string uid, IEnumerable<DataSaubBaseDto> dtos)
|
||||||
{
|
{
|
||||||
|
if (dtos == default || dtos.Count() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
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)
|
db.DataSaubBases.RemoveRange(oldDataSaubBase);
|
||||||
{
|
|
||||||
var dataSaub = mapper.Map<DataSaubBase>(item);
|
|
||||||
dataSaub.IdTelemetry = telemetryId;
|
|
||||||
db.DataSaubBases.Add(dataSaub);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var item in dtos)
|
||||||
|
{
|
||||||
|
var dataSaub = mapper.Map<DataSaubBase>(item);
|
||||||
|
dataSaub.IdTelemetry = telemetryId;
|
||||||
|
db.DataSaubBases.Add(dataSaub);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user