This commit is contained in:
@@ -147,6 +147,7 @@ namespace AyaNova.Biz
|
||||
ret.IsLockedAtServer = stat.Locked;
|
||||
ret.IsDirty = false;
|
||||
|
||||
|
||||
if (logTheGetEvent && ret != null)
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
|
||||
return ret;
|
||||
@@ -205,7 +206,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
try
|
||||
{
|
||||
WorkOrder dbObject = await WorkOrderGetAsync(id, false);
|
||||
WorkOrder dbObject = await ct.WorkOrder.AsNoTracking().Where(z => z.Id == id).FirstOrDefaultAsync();// WorkOrderGetAsync(id, false);
|
||||
if (dbObject == null)
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_FOUND);
|
||||
@@ -215,6 +216,10 @@ namespace AyaNova.Biz
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
//States collection
|
||||
if (!await StateDeleteAsync(id, transaction))
|
||||
return false;
|
||||
|
||||
//collect the child id's to delete
|
||||
var ItemIds = await ct.WorkOrderItem.AsNoTracking().Where(z => z.WorkOrderId == id).Select(z => z.Id).ToListAsync();
|
||||
|
||||
@@ -462,13 +467,23 @@ namespace AyaNova.Biz
|
||||
{
|
||||
var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
|
||||
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
|
||||
//query for this batch, comes back in db natural order unfortunately
|
||||
var batchResults = await ct.WorkOrder.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
||||
List<WorkOrder> batchResults = new List<WorkOrder>();
|
||||
foreach (long batchId in batch)
|
||||
batchResults.Add(await WorkOrderGetAsync(batchId, false));
|
||||
|
||||
//order the results back into original
|
||||
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||
|
||||
foreach (WorkOrder w in orderedList)
|
||||
{
|
||||
//TODO: populate viz and hydrate custom fields will need to be done in entire graph
|
||||
//so there should also be calls to items populate viz fields and on and on
|
||||
//ideally here should only need to call itemPopulatevizFields one by one to do it which in turn will call
|
||||
//grandchild *PopulatevizFields etc walking the graph
|
||||
|
||||
await WorkOrderPopulateVizFields(w);
|
||||
|
||||
//TODO: this will need to be replicated at every level where custom fields are supported
|
||||
var jo = JObject.FromObject(w);
|
||||
if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"]))
|
||||
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
||||
@@ -689,6 +704,40 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task StatePopulateVizFields(WorkOrderState o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
// (note: this would only ever be called when a workorder is deleted, there is no direct delete)
|
||||
internal async Task<bool> StateDeleteAsync(long workOrderId, IDbContextTransaction parentTransaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var stateList = await ct.WorkOrderState.AsNoTracking().Where(z => z.WorkOrderId == workOrderId).ToListAsync();
|
||||
|
||||
foreach (var wostate in stateList)
|
||||
{
|
||||
await StateHandlePotentialNotificationEvent(AyaEvent.Deleted, wostate);
|
||||
ct.WorkOrderState.Remove(wostate);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
throw;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -879,7 +928,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> ItemDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> ItemDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -977,6 +1026,14 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task ItemPopulateVizFields(WorkOrderItem o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -1172,7 +1229,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> ExpenseDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> ExpenseDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -1225,6 +1282,14 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task ItemPopulateVizFields(WorkOrderItemExpense o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -1420,7 +1485,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> LaborDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> LaborDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -1474,6 +1539,15 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task LaborPopulateVizFields(WorkOrderItemLabor o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -1671,7 +1745,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> LoanDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> LoanDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -1724,6 +1798,14 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task LoanPopulateVizFields(WorkOrderItemLoan o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -1932,7 +2014,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> OutsideServiceDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> OutsideServiceDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -1985,6 +2067,13 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task OutsideServicePopulateVizFields(WorkOrderItemOutsideService o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
@@ -2184,7 +2273,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> PartDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> PartDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -2236,7 +2325,13 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task PartPopulateVizFields(WorkOrderItemPart o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
@@ -2435,7 +2530,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> PartRequestDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> PartRequestDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -2464,6 +2559,15 @@ namespace AyaNova.Biz
|
||||
return true;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task PartRequestPopulateVizFields(WorkOrderItemPartRequest o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -2662,7 +2766,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> ScheduledUserDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> ScheduledUserDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -2691,6 +2795,14 @@ namespace AyaNova.Biz
|
||||
return true;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task ScheduledUserPopulateVizFields(WorkOrderItemScheduledUser o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -2889,7 +3001,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> TaskDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> TaskDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -2942,6 +3054,14 @@ namespace AyaNova.Biz
|
||||
return SearchParams;
|
||||
}
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task TaskPopulateVizFields(WorkOrderItemTask o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -3139,7 +3259,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> TravelDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> TravelDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
@@ -3194,6 +3314,14 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
//populate viz fields from provided object
|
||||
private async Task TravelPopulateVizFields(WorkOrderItemTravel o)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
// if (o.WorkOrderOverseerId != null)
|
||||
// o.WorkOrderOverseerViz = await ct.User.AsNoTracking().Where(x => x.Id == o.WorkOrderOverseerId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
@@ -3391,7 +3519,7 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> UnitDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<bool> UnitDeleteAsync(long id, IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user