DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs

46 lines
1.7 KiB
C#
Raw Normal View History

2022-04-08 13:10:06 +05:00
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
2022-10-06 13:49:20 +05:00
using System.Linq;
2022-04-11 18:00:34 +05:00
namespace AsbCloudInfrastructure.Services.SAUB
{
#nullable enable
2022-04-11 18:00:34 +05:00
public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSaubDto, TelemetryDataSaub>
{
private readonly ITelemetryUserService telemetryUserService;
public TelemetryDataSaubService(
IAsbCloudDbContext db,
ITelemetryService telemetryService,
ITelemetryUserService telemetryUserService,
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache)
: base(db, telemetryService, telemetryDataCache)
{
this.telemetryUserService = telemetryUserService;
}
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
{
var entity = src.Adapt<TelemetryDataSaub>();
var telemetryUser = telemetryUserService
.GetUsers(src.IdTelemetry, u => (u.Name == src.User || u.Surname == src.User))
.FirstOrDefault();
entity.IdUser = telemetryUser?.Id;
2022-04-08 13:10:06 +05:00
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
return entity;
}
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
{
var dto = src.Adapt<TelemetryDataSaubDto>();
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser??int.MinValue);
dto.User = telemetryUser?.MakeDisplayName();
2022-04-08 13:10:06 +05:00
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
return dto;
}
}
#nullable disable
}