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 cacheTelemetryUsers; public TelemetryUserService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService) { this.telemetryService = telemetryService; cacheTelemetryUsers = cacheDb.GetCachedTable((AsbCloudDbContext)db); } public void Upsert(string uid, IEnumerable 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); } } }