Изменение даты для MeasureDto

This commit is contained in:
Olga Nemt 2024-03-21 11:42:07 +05:00
parent 593183ec87
commit ef9466f90d
2 changed files with 6 additions and 7 deletions

View File

@ -36,7 +36,7 @@ namespace AsbCloudApp.Data
/// отметка времени замера
/// </summary>
[Required]
public DateTime Timestamp { get; set; }
public DateTimeOffset Timestamp { get; set; }
/// <summary>
/// данные замера

View File

@ -87,8 +87,7 @@ namespace AsbCloudInfrastructure.Services
throw new ArgumentInvalidException(nameof(dto), "wrong idCategory");
if (!dto.Data.Any())
throw new ArgumentInvalidException(nameof(dto), "data.data is not optional");
var timezone = wellService.GetTimezone(idWell);
var entity = Convert(dto, timezone.Hours);
var entity = Convert(dto);
entity.IdWell = idWell;
db.Measures.Add(entity);
return db.SaveChangesAsync(token);
@ -110,7 +109,7 @@ namespace AsbCloudInfrastructure.Services
var timezone = wellService.GetTimezone(idWell);
entity.IdWell = idWell;
entity.Timestamp = dto.Timestamp.ToUtcDateTimeOffset(timezone.Hours);
entity.Timestamp = dto.Timestamp.ToOffset(TimeSpan.FromHours(timezone.Hours));
entity.Data = dto.Data.Adapt<RawData>();
return await db.SaveChangesAsync(token).ConfigureAwait(false);
@ -142,13 +141,13 @@ namespace AsbCloudInfrastructure.Services
{
var dto = entity.Adapt<MeasureDto>();
dto.CategoryName = entity.Category?.Name ?? String.Empty;
dto.Timestamp = entity.Timestamp.ToRemoteDateTime(hours);
dto.Timestamp = entity.Timestamp.ToOffset(TimeSpan.FromHours(hours));
return dto;
}
private Measure Convert(MeasureDto dto, double hours)
private Measure Convert(MeasureDto dto)
{
var entity = dto.Adapt<Measure>();
entity.Timestamp = dto.Timestamp.ToUtcDateTimeOffset(hours);
entity.Timestamp = dto.Timestamp.ToUniversalTime();
return entity;
}
}