CS2-16: Fix критической ошибки при получении двух юзеров с одинаковым Id

This commit is contained in:
KharchenkoVV 2021-05-28 15:04:11 +05:00
parent b21fe640e0
commit 3a4a27942a
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,20 @@
using AsbCloudApp.Data;
using System.Collections.Generic;
namespace AsbCloudApp.Comparators
{
public class TelemetryUserDtoComparer : IEqualityComparer<TelemetryUserDto>
{
public bool Equals(TelemetryUserDto prevUser, TelemetryUserDto nextUser)
{
if (prevUser is null || nextUser is null)
return false;
else if (prevUser.Id == nextUser.Id)
return true;
else
return false;
}
public int GetHashCode(TelemetryUserDto user) => user.Id.GetHashCode();
}
}

View File

@ -1,5 +1,6 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudApp.Comparators;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using System.Collections.Generic;
@ -25,6 +26,8 @@ namespace AsbCloudInfrastructure.Services
if (!dtos.Any())
return;
dtos = dtos.Distinct(new TelemetryUserDtoComparer());
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
var ids = dtos.Select(e => e.Id).ToList();