forked from ddrilling/AsbCloudServer
Add TryGetTimezone methods.
EnshureTimezonesIsSet() sets default timezone if can't find correct one. Edit WellDto to fix exception by constr: FK_t_well_t_well_type_id_well_type. Make IdWellType optional.
This commit is contained in:
parent
0687efa5af
commit
90a0aa9e5b
@ -10,7 +10,7 @@ namespace AsbCloudApp.Data
|
|||||||
public double? Longitude { get; set; }
|
public double? Longitude { get; set; }
|
||||||
public SimpleTimezoneDto Timezone { get; set; }
|
public SimpleTimezoneDto Timezone { get; set; }
|
||||||
public string WellType { get; set; }
|
public string WellType { get; set; }
|
||||||
public int IdWellType { get; set; }
|
public int? IdWellType { get; set; }
|
||||||
public int? IdCluster { get; set; }
|
public int? IdCluster { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -184,7 +184,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
entity.IdTelemetry = entity.IdTelemetry ?? dto.IdTelemetry ?? dto.Telemetry?.Id;
|
entity.IdTelemetry = entity.IdTelemetry ?? dto.IdTelemetry ?? dto.Telemetry?.Id;
|
||||||
|
|
||||||
if (dto.Timezone is null)
|
if (dto.Timezone is null)
|
||||||
entity.Timezone = GetTimezone(dto.Id).Adapt<SimpleTimezone>();
|
if (TryGetTimezone(dto.Id, out var timezoneDto))
|
||||||
|
entity.Timezone = timezoneDto.Adapt<SimpleTimezone>();
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@ -197,7 +198,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var dto = base.Convert(entity);
|
var dto = base.Convert(entity);
|
||||||
|
|
||||||
if (entity.Timezone is null)
|
if (entity.Timezone is null)
|
||||||
dto.Timezone = GetTimezone(entity);
|
if(TryGetTimezone(entity, out var timezone))
|
||||||
|
dto.Timezone = timezone;
|
||||||
|
|
||||||
dto.WellType = entity.WellType?.Caption;
|
dto.WellType = entity.WellType?.Caption;
|
||||||
dto.Cluster = entity.Cluster?.Caption;
|
dto.Cluster = entity.Cluster?.Caption;
|
||||||
@ -219,7 +221,18 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var wells = Cache.Where(w => w.Timezone is null).ToList();
|
var wells = Cache.Where(w => w.Timezone is null).ToList();
|
||||||
foreach (var well in wells)
|
foreach (var well in wells)
|
||||||
well.Timezone = GetTimezone(well).Adapt<SimpleTimezone>();
|
{
|
||||||
|
if (TryGetTimezone(well, out var timezone))
|
||||||
|
well.Timezone = timezone.Adapt<SimpleTimezone>();
|
||||||
|
else
|
||||||
|
well.Timezone = new SimpleTimezone
|
||||||
|
{
|
||||||
|
Hours = 5,
|
||||||
|
IsOverride = false,
|
||||||
|
TimeZoneId = "Assumed",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var wellsWithTz = wells.Where(w => w.Timezone is not null);
|
var wellsWithTz = wells.Where(w => w.Timezone is not null);
|
||||||
if (wellsWithTz.Any())
|
if (wellsWithTz.Any())
|
||||||
{
|
{
|
||||||
@ -228,6 +241,20 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryGetTimezone(int idWell, out SimpleTimezoneDto timezone)
|
||||||
|
{
|
||||||
|
timezone = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
timezone = GetTimezone(idWell);
|
||||||
|
return timezone is not null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SimpleTimezoneDto GetTimezone(int idWell)
|
public SimpleTimezoneDto GetTimezone(int idWell)
|
||||||
{
|
{
|
||||||
var well = Cache.FirstOrDefault(c => c.Id == idWell);
|
var well = Cache.FirstOrDefault(c => c.Id == idWell);
|
||||||
@ -236,6 +263,20 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return GetTimezone(well);
|
return GetTimezone(well);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryGetTimezone(Well well, out SimpleTimezoneDto timezone)
|
||||||
|
{
|
||||||
|
timezone = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
timezone = GetTimezone(well);
|
||||||
|
return timezone is not null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SimpleTimezoneDto GetTimezone(Well well)
|
private SimpleTimezoneDto GetTimezone(Well well)
|
||||||
{
|
{
|
||||||
if (well == null)
|
if (well == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user