This commit is contained in:
2021-07-20 00:04:41 +00:00
parent 1ac224c43f
commit 9d5321c4e3
2 changed files with 43 additions and 24 deletions

View File

@@ -162,7 +162,7 @@ namespace AyaNova.Biz
} }
await transaction.CommitAsync(); await transaction.CommitAsync();
if (populateViz) if (populateViz)
await WorkOrderPopulateVizFields(newObject, true); await WorkOrderPopulateVizFields(newObject, true, false);
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject); await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject; return newObject;
@@ -282,7 +282,7 @@ namespace AyaNova.Biz
} }
if (populateDisplayFields) if (populateDisplayFields)
await WorkOrderPopulateVizFields(ret, false); await WorkOrderPopulateVizFields(ret, false, false);
if (logTheGetEvent && ret != null) if (logTheGetEvent && ret != null)
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
@@ -344,7 +344,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
await WorkOrderSearchIndexAsync(putObject, false); await WorkOrderSearchIndexAsync(putObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
await WorkOrderPopulateVizFields(putObject, true);//doing this here ahead of notification because notification may require the viz field lookup anyway and afaict no harm in it await WorkOrderPopulateVizFields(putObject, true, false);//doing this here ahead of notification because notification may require the viz field lookup anyway and afaict no harm in it
await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject); await WorkOrderHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
return putObject; return putObject;
} }
@@ -864,7 +864,7 @@ namespace AyaNova.Biz
// (returns workorder consisting only of the path from child or grandchild up to header populated // (returns workorder consisting only of the path from child or grandchild up to header populated
// with display data for reporting) // with display data for reporting)
// //
internal async Task<WorkOrder> WorkOrderGetPartialAsync(AyaType ayaType, long id, bool includeWoItemDescendants) internal async Task<WorkOrder> WorkOrderGetPartialAsync(AyaType ayaType, long id, bool includeWoItemDescendants, bool populateForReporting)
{ {
//if it's the entire workorder just get, populate and return as normal //if it's the entire workorder just get, populate and return as normal
if (ayaType == AyaType.WorkOrder) if (ayaType == AyaType.WorkOrder)
@@ -904,12 +904,6 @@ namespace AyaNova.Biz
else else
{ {
//get the single workorder item required //get the single workorder item required
woitem = await ct.WorkOrderItem.AsNoTracking().SingleOrDefaultAsync(x => x.Id == wid.WorkOrderItemId); woitem = await ct.WorkOrderItem.AsNoTracking().SingleOrDefaultAsync(x => x.Id == wid.WorkOrderItemId);
@@ -951,7 +945,7 @@ namespace AyaNova.Biz
if (woitem != null) if (woitem != null)
ret.Items.Add(woitem); ret.Items.Add(woitem);
await WorkOrderPopulateVizFields(ret, false); await WorkOrderPopulateVizFields(ret, false, populateForReporting);
return ret; return ret;
} }
@@ -973,7 +967,7 @@ namespace AyaNova.Biz
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray(); idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
List<WorkOrder> batchResults = new List<WorkOrder>(); List<WorkOrder> batchResults = new List<WorkOrder>();
foreach (long batchId in batch) foreach (long batchId in batch)
batchResults.Add(await WorkOrderGetPartialAsync(dataListSelectedRequest.AType, batchId, dataListSelectedRequest.IncludeWoItemDescendants)); batchResults.Add(await WorkOrderGetPartialAsync(dataListSelectedRequest.AType, batchId, dataListSelectedRequest.IncludeWoItemDescendants, true));
#region unnecessary shit removed #region unnecessary shit removed
//This is unnecessary because the re-ordering bit is only needed when the records are fetched in batches directly from the sql server as they //This is unnecessary because the re-ordering bit is only needed when the records are fetched in batches directly from the sql server as they
@@ -1064,7 +1058,7 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//VIZ POPULATE //VIZ POPULATE
// //
private async Task WorkOrderPopulateVizFields(WorkOrder o, bool headerOnly) private async Task WorkOrderPopulateVizFields(WorkOrder o, bool headerOnly, bool populateForReporting)
{ {
@@ -1081,7 +1075,7 @@ namespace AyaNova.Biz
foreach (var v in o.States) foreach (var v in o.States)
await StatePopulateVizFields(v); await StatePopulateVizFields(v);
foreach (var v in o.Items) foreach (var v in o.Items)
await ItemPopulateVizFields(v); await ItemPopulateVizFields(v, populateForReporting);
} }
//popup Alert notes //popup Alert notes
@@ -1946,7 +1940,7 @@ namespace AyaNova.Biz
await ItemSearchIndexAsync(newObject, true); await ItemSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await ItemHandlePotentialNotificationEvent(AyaEvent.Created, newObject); await ItemHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await ItemPopulateVizFields(newObject); await ItemPopulateVizFields(newObject, false);
return newObject; return newObject;
} }
} }
@@ -2036,7 +2030,7 @@ namespace AyaNova.Biz
await ItemSearchIndexAsync(putObject, false); await ItemSearchIndexAsync(putObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
await ItemHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject); await ItemHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
await ItemPopulateVizFields(putObject); await ItemPopulateVizFields(putObject, false);
return putObject; return putObject;
} }
@@ -2148,7 +2142,7 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//VIZ POPULATE //VIZ POPULATE
// //
private async Task ItemPopulateVizFields(WorkOrderItem o) private async Task ItemPopulateVizFields(WorkOrderItem o, bool populateForReporting)
{ {
// if (o.WorkOrderOverseerId != null) // if (o.WorkOrderOverseerId != null)
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync(); // o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
@@ -2172,7 +2166,7 @@ namespace AyaNova.Biz
foreach (var v in o.Travels) foreach (var v in o.Travels)
await TravelPopulateVizFields(v); await TravelPopulateVizFields(v);
foreach (var v in o.Units) foreach (var v in o.Units)
await UnitPopulateVizFields(v); await UnitPopulateVizFields(v, populateForReporting);
} }
@@ -5971,7 +5965,7 @@ namespace AyaNova.Biz
await UnitSearchIndexAsync(newObject, true); await UnitSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject); await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await UnitPopulateVizFields(newObject); await UnitPopulateVizFields(newObject, false);
return newObject; return newObject;
} }
@@ -6030,9 +6024,9 @@ namespace AyaNova.Biz
await UnitSearchIndexAsync(putObject, false); await UnitSearchIndexAsync(putObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject); await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
await UnitPopulateVizFields(putObject); await UnitPopulateVizFields(putObject, false);
return putObject; return putObject;
} }
@@ -6131,12 +6125,25 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//VIZ POPULATE //VIZ POPULATE
// //
private async Task UnitPopulateVizFields(WorkOrderItemUnit o) private async Task UnitPopulateVizFields(WorkOrderItemUnit o, bool populateForReporting)
{ {
var unitInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == o.UnitId).Select(x => new { x.Serial, x.Description, x.UnitModelId }).FirstOrDefaultAsync(); var unitInfo = await ct.Unit.AsNoTracking()
.Where(x => x.Id == o.UnitId)
.Select(x => new { x.Serial, x.Description, x.UnitModelId, x.Address, x.City, x.Region, x.Country, x.Latitude, x.Longitude })
.FirstOrDefaultAsync();
o.UnitViz = unitInfo.Serial; o.UnitViz = unitInfo.Serial;
o.UnitDescriptionViz = unitInfo.Description; o.UnitDescriptionViz = unitInfo.Description;
if (populateForReporting)
{
o.AddressViz = unitInfo.Address;
o.CityViz = unitInfo.City;
o.RegionViz = unitInfo.Region;
o.CountryViz = unitInfo.Country;
o.LatitudeViz = unitInfo.Latitude;
o.LongitudeViz = unitInfo.Longitude;
}
if (unitInfo.UnitModelId != null) if (unitInfo.UnitModelId != null)
{ {
var unitModelInfo = await ct.UnitModel.AsNoTracking().Where(x => x.Id == unitInfo.UnitModelId).Select(x => new { x.Name, x.VendorId, x.Number }).FirstOrDefaultAsync(); var unitModelInfo = await ct.UnitModel.AsNoTracking().Where(x => x.Id == unitInfo.UnitModelId).Select(x => new { x.Name, x.VendorId, x.Number }).FirstOrDefaultAsync();

View File

@@ -34,7 +34,19 @@ namespace AyaNova.Models
[NotMapped] [NotMapped]
public string UnitDescriptionViz { get; set; } public string UnitDescriptionViz { get; set; }
//PHYSICAL ADDRESS
[NotMapped]
public string AddressViz { get; set; }
[NotMapped]
public string CityViz { get; set; }
[NotMapped]
public string RegionViz { get; set; }
[NotMapped]
public string CountryViz { get; set; }
[NotMapped]
public decimal? LatitudeViz { get; set; }
[NotMapped]
public decimal? LongitudeViz { get; set; }
//workaround for notification //workaround for notification
[NotMapped, JsonIgnore] [NotMapped, JsonIgnore]