forked from ddrilling/AsbCloudServer
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using AsbCloudApp.Comparators;
|
|
using AsbCloudApp.Data.SAUB;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services.SAUB
|
|
{
|
|
public class TelemetryUserService : ITelemetryUserService
|
|
{
|
|
private readonly ITelemetryService telemetryService;
|
|
private readonly CacheTable<TelemetryUser> cacheTelemetryUsers;
|
|
|
|
public TelemetryUserService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
|
|
{
|
|
this.telemetryService = telemetryService;
|
|
cacheTelemetryUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
|
|
}
|
|
|
|
public void Upsert(string uid, IEnumerable<TelemetryUserDto> dtos)
|
|
{
|
|
if (!dtos.Any())
|
|
return;
|
|
|
|
var telemetryId = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
|
|
|
var entities = dtos.Distinct(new TelemetryUserDtoComparer()).Select(dto => new TelemetryUser
|
|
{
|
|
IdUser = dto.Id,
|
|
IdTelemetry = telemetryId,
|
|
Level = dto.Level,
|
|
Name = dto.Name,
|
|
Patronymic = dto.Patronymic,
|
|
Surname = dto.Surname,
|
|
});
|
|
cacheTelemetryUsers.Upsert(entities);
|
|
}
|
|
}
|
|
}
|