DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/TelemetryUserService.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2021-04-23 10:21:25 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudApp.Comparators;
2021-04-23 10:21:25 +05:00
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services
{
public class TelemetryUserService : ITelemetryUserService
{
private readonly ITelemetryService telemetryService;
2021-07-16 09:15:10 +05:00
private readonly CacheTable<TelemetryUser> cacheTelemetryUsers;
2021-04-23 10:21:25 +05:00
public TelemetryUserService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
{
this.telemetryService = telemetryService;
2021-07-16 09:15:10 +05:00
cacheTelemetryUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
2021-04-23 10:21:25 +05:00
}
public void Upsert(string uid, IEnumerable<TelemetryUserDto> dtos)
{
2021-05-20 11:17:55 +05:00
if (!dtos.Any())
2021-04-23 10:21:25 +05:00
return;
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
2021-07-16 09:15:10 +05:00
var entities = dtos.Distinct(new TelemetryUserDtoComparer()).Select(dto => new TelemetryUser
2021-04-23 10:21:25 +05:00
{
2021-07-16 09:15:10 +05:00
IdUser = dto.Id,
IdTelemetry = telemetryId,
Level = dto.Level,
Name = dto.Name,
Patronymic = dto.Patronymic,
Surname = dto.Surname,
});
cacheTelemetryUsers.Upsert(entities);
2021-04-23 10:21:25 +05:00
}
}
}