This commit is contained in:
@@ -435,77 +435,84 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
try
|
||||||
|
|
||||||
if (existingId == 0)
|
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
{
|
|
||||||
//import this record
|
|
||||||
var Target = j.ToObject<Customer>(jsset);
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
|
|
||||||
//Set linked objects
|
if (existingId == 0)
|
||||||
if (Target.BillHeadOffice)
|
{
|
||||||
|
if (importData.DoImport)
|
||||||
{
|
{
|
||||||
if (JsonUtil.JTokenIsNullOrEmpty(j["HeadOfficeViz"]))
|
//import this record
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz");
|
var Target = j.ToObject<Customer>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
|
||||||
|
//Set linked objects
|
||||||
|
if (Target.BillHeadOffice)
|
||||||
|
{
|
||||||
|
if (JsonUtil.JTokenIsNullOrEmpty(j["HeadOfficeViz"]))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//if it's not found, it will be zero which will fail validation with a clean error
|
||||||
|
Target.HeadOfficeId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["HeadOfficeViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (Target.HeadOfficeId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "HeadOfficeViz", $"'{(string)j["HeadOfficeViz"]}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
||||||
|
{
|
||||||
|
Target.ContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (Target.ContractId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
||||||
|
|
||||||
|
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
||||||
|
Target.ContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
||||||
|
else
|
||||||
|
Target.ContractExpires = (DateTime)j["ContractExpires"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//if it's not found, it will be zero which will fail validation with a clean error
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
Target.HeadOfficeId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["HeadOfficeViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
if (Target.HeadOfficeId == 0)
|
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "HeadOfficeViz", $"'{(string)j["HeadOfficeViz"]}'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
{
|
{
|
||||||
Target.ContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
//update this record with any data provided
|
||||||
if (Target.ContractId == 0)
|
//load existing record
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<Customer>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
if (res == null)
|
||||||
Target.ContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Target.ContractExpires = (DateTime)j["ContractExpires"];
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<Customer>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -353,65 +353,72 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
long existingId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
try
|
||||||
|
|
||||||
if (existingId == 0)
|
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
long existingId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (existingId == 0)
|
||||||
{
|
{
|
||||||
//import this record
|
if (importData.DoImport)
|
||||||
var o = j.ToObject<HeadOffice>(jsset);
|
|
||||||
o.Tags.Add(ImportTag);
|
|
||||||
|
|
||||||
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
|
||||||
{
|
{
|
||||||
o.ContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
//import this record
|
||||||
if (o.ContractId == 0)
|
var o = j.ToObject<HeadOffice>(jsset);
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
o.Tags.Add(ImportTag);
|
||||||
|
|
||||||
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
|
||||||
o.ContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
||||||
|
{
|
||||||
|
o.ContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (o.ContractId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
||||||
|
|
||||||
|
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
||||||
|
o.ContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
||||||
|
else
|
||||||
|
o.ContractExpires = (DateTime)j["ContractExpires"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await CreateAsync(o);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {o.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
o.ContractExpires = (DateTime)j["ContractExpires"];
|
{
|
||||||
|
ImportResult.Add($"✔️ {o.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
|
{
|
||||||
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var target = await GetAsync((long)existingId);
|
||||||
|
var source = j.ToObject<HeadOffice>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(source, target, propertiesToUpdate);
|
||||||
|
var res = await PutAsync(target);
|
||||||
|
|
||||||
var res = await CreateAsync(o);
|
if (res == null)
|
||||||
if (res == null)
|
{
|
||||||
{
|
ImportResult.Add($"❌ {target.Name} - {this.GetErrorsAsString()}");
|
||||||
ImportResult.Add($"❌ {o.Name}\r\n{this.GetErrorsAsString()}");
|
this.ClearErrors();
|
||||||
this.ClearErrors();
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
ImportResult.Add($"✔️ {target.Name}");
|
||||||
ImportResult.Add($"✔️ {o.Name}");
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var target = await GetAsync((long)existingId);
|
|
||||||
var source = j.ToObject<HeadOffice>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(source, target, propertiesToUpdate);
|
|
||||||
var res = await PutAsync(target);
|
|
||||||
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -392,94 +392,101 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
//Compile Items collection if specified
|
|
||||||
var ImportPartAssemblyItems = new List<PartAssemblyItem>();
|
|
||||||
if (j["Items"] != null)
|
|
||||||
{
|
{
|
||||||
//hydrate from collection
|
|
||||||
foreach (JToken t in j["Items"])
|
//Compile Items collection if specified
|
||||||
|
var ImportPartAssemblyItems = new List<PartAssemblyItem>();
|
||||||
|
if (j["Items"] != null)
|
||||||
{
|
{
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(t["PartNameViz"]))//part name is mandatory, the quantity can be inferred
|
//hydrate from collection
|
||||||
|
foreach (JToken t in j["Items"])
|
||||||
{
|
{
|
||||||
decimal parsedQuantity = 0;
|
if (!JsonUtil.JTokenIsNullOrEmpty(t["PartNameViz"]))//part name is mandatory, the quantity can be inferred
|
||||||
//a name was specified so attempt to find it
|
{
|
||||||
var parsedPartId = await ct.Part.AsNoTracking().Where(z => z.Name == (string)t["PartNameViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
decimal parsedQuantity = 0;
|
||||||
if (parsedPartId == 0)
|
//a name was specified so attempt to find it
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "PartNameViz", $"'{(string)t["PartNameViz"]}'");
|
var parsedPartId = await ct.Part.AsNoTracking().Where(z => z.Name == (string)t["PartNameViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (parsedPartId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "PartNameViz", $"'{(string)t["PartNameViz"]}'");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//we have a valid part id now parse out quantity or set to zero if not specified
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(t["Quantity"]))
|
||||||
|
{
|
||||||
|
parsedQuantity = (decimal)t["Quantity"];
|
||||||
|
}
|
||||||
|
ImportPartAssemblyItems.Add(new PartAssemblyItem() { PartAssemblyId = 0, PartId = parsedPartId, Quantity = parsedQuantity });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
j["Items"] = null;//strip it out so it doesn't get automatically converted into parsed object later
|
||||||
|
}
|
||||||
|
|
||||||
|
long existingId = await ct.PartAssembly.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (existingId == 0)
|
||||||
|
{
|
||||||
|
if (importData.DoImport)
|
||||||
|
{
|
||||||
|
//import this record
|
||||||
|
var Target = j.ToObject<PartAssembly>(jsset);
|
||||||
|
if (Target.Items == null)
|
||||||
|
Target.Items = new List<PartAssemblyItem>();
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
|
||||||
|
if (j["Items"] != null)
|
||||||
|
foreach (PartAssemblyItem ipi in ImportPartAssemblyItems)
|
||||||
|
Target.Items.Add(ipi);
|
||||||
|
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//we have a valid part id now parse out quantity or set to zero if not specified
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(t["Quantity"]))
|
|
||||||
{
|
|
||||||
parsedQuantity = (decimal)t["Quantity"];
|
|
||||||
}
|
|
||||||
ImportPartAssemblyItems.Add(new PartAssemblyItem() { PartAssemblyId = 0, PartId = parsedPartId, Quantity = parsedQuantity });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j["Items"] = null;//strip it out so it doesn't get automatically converted into parsed object later
|
else
|
||||||
}
|
|
||||||
|
|
||||||
long existingId = await ct.PartAssembly.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (existingId == 0)
|
|
||||||
{
|
|
||||||
if (importData.DoImport)
|
|
||||||
{
|
{
|
||||||
//import this record
|
if (importData.DoUpdate)
|
||||||
var Target = j.ToObject<PartAssembly>(jsset);
|
|
||||||
if (Target.Items == null)
|
|
||||||
Target.Items = new List<PartAssemblyItem>();
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
|
|
||||||
if (j["Items"] != null)
|
|
||||||
foreach (PartAssemblyItem ipi in ImportPartAssemblyItems)
|
|
||||||
Target.Items.Add(ipi);
|
|
||||||
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//update this record with any data provided
|
||||||
this.ClearErrors();
|
//load existing record
|
||||||
}
|
var Target = await GetAsync((long)existingId);
|
||||||
else
|
var Source = j.ToObject<PartAssembly>(jsset);
|
||||||
{
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
propertiesToUpdate.Remove("Name");
|
||||||
|
propertiesToUpdate.Remove("Items");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
if (j["Items"] != null)
|
||||||
|
{
|
||||||
|
Target.Items.Clear();
|
||||||
|
foreach (PartAssemblyItem ipi in ImportPartAssemblyItems)
|
||||||
|
Target.Items.Add(ipi);
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<PartAssembly>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
propertiesToUpdate.Remove("Items");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
if (j["Items"] != null)
|
|
||||||
{
|
|
||||||
Target.Items.Clear();
|
|
||||||
foreach (PartAssemblyItem ipi in ImportPartAssemblyItems)
|
|
||||||
Target.Items.Add(ipi);
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -566,121 +566,128 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
//Compile linked objects if specified
|
|
||||||
long? ImportManufacturerId = -1;//default meaning not included / don't set
|
|
||||||
if (j["ManufacturerViz"] != null)
|
|
||||||
{
|
{
|
||||||
//something was specified, may be deliberate attempt to null it out so default to that
|
|
||||||
ImportManufacturerId = null;
|
//Compile linked objects if specified
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ManufacturerViz"]))
|
long? ImportManufacturerId = -1;//default meaning not included / don't set
|
||||||
|
if (j["ManufacturerViz"] != null)
|
||||||
{
|
{
|
||||||
//a name was specified so attempt to find it
|
//something was specified, may be deliberate attempt to null it out so default to that
|
||||||
ImportManufacturerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["ManufacturerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
ImportManufacturerId = null;
|
||||||
if (ImportManufacturerId == 0)
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ManufacturerViz"]))
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "ManufacturerViz", $"'{(string)j["ManufacturerViz"]}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long? ImportWholeSalerId = -1;
|
|
||||||
if (j["WholeSalerViz"] != null)
|
|
||||||
{
|
|
||||||
ImportWholeSalerId = null;
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["WholeSalerViz"]))
|
|
||||||
{
|
|
||||||
ImportWholeSalerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["WholeSalerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
if (ImportWholeSalerId == 0)
|
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "WholeSalerViz", $"'{(string)j["WholeSalerViz"]}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long? ImportAlternativeWholeSalerId = -1;
|
|
||||||
if (j["AlternativeWholeSalerViz"] != null)
|
|
||||||
{
|
|
||||||
ImportAlternativeWholeSalerId = null;
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["AlternativeWholeSalerViz"]))
|
|
||||||
{
|
|
||||||
ImportAlternativeWholeSalerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["AlternativeWholeSalerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
if (ImportAlternativeWholeSalerId == 0)
|
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "AlternativeWholeSalerViz", $"'{(string)j["AlternativeWholeSalerViz"]}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> ImportSerials = new List<string>();
|
|
||||||
if (j["PartSerialsViz"] != null)
|
|
||||||
{
|
|
||||||
var raw = (string)j["PartSerialsViz"];
|
|
||||||
if (!string.IsNullOrWhiteSpace(raw))
|
|
||||||
ImportSerials = raw.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long existingId = await ct.Part.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (existingId == 0)
|
|
||||||
{
|
|
||||||
if (importData.DoImport)
|
|
||||||
{
|
|
||||||
//import this record
|
|
||||||
var Target = j.ToObject<Part>(jsset);
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
|
|
||||||
if (ImportManufacturerId != -1)
|
|
||||||
Target.ManufacturerId = ImportManufacturerId;
|
|
||||||
|
|
||||||
if (ImportWholeSalerId != -1)
|
|
||||||
Target.WholeSalerId = ImportWholeSalerId;
|
|
||||||
|
|
||||||
if (ImportAlternativeWholeSalerId != -1)
|
|
||||||
Target.AlternativeWholeSalerId = ImportAlternativeWholeSalerId;
|
|
||||||
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//a name was specified so attempt to find it
|
||||||
this.ClearErrors();
|
ImportManufacturerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["ManufacturerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportManufacturerId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ManufacturerViz", $"'{(string)j["ManufacturerViz"]}'");
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
long? ImportWholeSalerId = -1;
|
||||||
|
if (j["WholeSalerViz"] != null)
|
||||||
|
{
|
||||||
|
ImportWholeSalerId = null;
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["WholeSalerViz"]))
|
||||||
{
|
{
|
||||||
if (j["PartSerialsViz"] != null)
|
ImportWholeSalerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["WholeSalerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
await PutSerialsAsync(res.Id, ImportSerials);
|
if (ImportWholeSalerId == 0)
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
AddError(ApiErrorCode.NOT_FOUND, "WholeSalerViz", $"'{(string)j["WholeSalerViz"]}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long? ImportAlternativeWholeSalerId = -1;
|
||||||
|
if (j["AlternativeWholeSalerViz"] != null)
|
||||||
|
{
|
||||||
|
ImportAlternativeWholeSalerId = null;
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["AlternativeWholeSalerViz"]))
|
||||||
|
{
|
||||||
|
ImportAlternativeWholeSalerId = await ct.Vendor.AsNoTracking().Where(z => z.Name == (string)j["AlternativeWholeSalerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportAlternativeWholeSalerId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "AlternativeWholeSalerViz", $"'{(string)j["AlternativeWholeSalerViz"]}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> ImportSerials = new List<string>();
|
||||||
|
if (j["PartSerialsViz"] != null)
|
||||||
|
{
|
||||||
|
var raw = (string)j["PartSerialsViz"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(raw))
|
||||||
|
ImportSerials = raw.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long existingId = await ct.Part.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (existingId == 0)
|
||||||
|
{
|
||||||
|
if (importData.DoImport)
|
||||||
|
{
|
||||||
|
//import this record
|
||||||
|
var Target = j.ToObject<Part>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
|
||||||
|
if (ImportManufacturerId != -1)
|
||||||
|
Target.ManufacturerId = ImportManufacturerId;
|
||||||
|
|
||||||
|
if (ImportWholeSalerId != -1)
|
||||||
|
Target.WholeSalerId = ImportWholeSalerId;
|
||||||
|
|
||||||
|
if (ImportAlternativeWholeSalerId != -1)
|
||||||
|
Target.AlternativeWholeSalerId = ImportAlternativeWholeSalerId;
|
||||||
|
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (j["PartSerialsViz"] != null)
|
||||||
|
await PutSerialsAsync(res.Id, ImportSerials);
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
|
{
|
||||||
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<Part>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
if (ImportManufacturerId != -1)
|
||||||
|
Target.ManufacturerId = ImportManufacturerId;
|
||||||
|
if (ImportWholeSalerId != -1)
|
||||||
|
Target.WholeSalerId = ImportWholeSalerId;
|
||||||
|
if (ImportAlternativeWholeSalerId != -1)
|
||||||
|
Target.AlternativeWholeSalerId = ImportAlternativeWholeSalerId;
|
||||||
|
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (j["PartSerialsViz"] != null)
|
||||||
|
await PutSerialsAsync(res.Id, ImportSerials);
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<Part>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
if (ImportManufacturerId != -1)
|
|
||||||
Target.ManufacturerId = ImportManufacturerId;
|
|
||||||
if (ImportWholeSalerId != -1)
|
|
||||||
Target.WholeSalerId = ImportWholeSalerId;
|
|
||||||
if (ImportAlternativeWholeSalerId != -1)
|
|
||||||
Target.AlternativeWholeSalerId = ImportAlternativeWholeSalerId;
|
|
||||||
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (j["PartSerialsViz"] != null)
|
|
||||||
await PutSerialsAsync(res.Id, ImportSerials);
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -335,48 +335,55 @@ namespace AyaNova.Biz
|
|||||||
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
long existingId = await ct.PartWarehouse.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
try
|
||||||
if (existingId == 0)
|
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
long existingId = await ct.PartWarehouse.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (existingId == 0)
|
||||||
{
|
{
|
||||||
//import this record
|
if (importData.DoImport)
|
||||||
var Target = j.ToObject<PartWarehouse>(jsset);
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//import this record
|
||||||
this.ClearErrors();
|
var Target = j.ToObject<PartWarehouse>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<PartWarehouse>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<PartWarehouse>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -335,69 +335,76 @@ namespace AyaNova.Biz
|
|||||||
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
//Compile linked objects if specified
|
|
||||||
long? ImportProjectOverseer = -1;//default meaning not included / don't set
|
|
||||||
if (j["ProjectOverseerViz"] != null)
|
|
||||||
{
|
{
|
||||||
//something was specified, may be deliberate attempt to null it out so default to that
|
|
||||||
ImportProjectOverseer = null;
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ProjectOverseerViz"]))
|
|
||||||
{
|
|
||||||
//a name was specified so attempt to find it
|
|
||||||
ImportProjectOverseer = await ct.User.AsNoTracking().Where(z => z.Name == (string)j["ProjectOverseerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
if (ImportProjectOverseer == 0)
|
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "ProjectOverseerViz", $"'{(string)j["ProjectOverseerViz"]}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//Compile linked objects if specified
|
||||||
long existingId = await ct.Project.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
long? ImportProjectOverseer = -1;//default meaning not included / don't set
|
||||||
if (existingId == 0)
|
if (j["ProjectOverseerViz"] != null)
|
||||||
{
|
|
||||||
if (importData.DoImport)
|
|
||||||
{
|
{
|
||||||
//import this record
|
//something was specified, may be deliberate attempt to null it out so default to that
|
||||||
var Target = j.ToObject<Project>(jsset);
|
ImportProjectOverseer = null;
|
||||||
Target.Tags.Add(ImportTag);
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ProjectOverseerViz"]))
|
||||||
if (ImportProjectOverseer != -1)
|
|
||||||
Target.ProjectOverseerId = ImportProjectOverseer;
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//a name was specified so attempt to find it
|
||||||
this.ClearErrors();
|
ImportProjectOverseer = await ct.User.AsNoTracking().Where(z => z.Name == (string)j["ProjectOverseerViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportProjectOverseer == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ProjectOverseerViz", $"'{(string)j["ProjectOverseerViz"]}'");
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long existingId = await ct.Project.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (existingId == 0)
|
||||||
|
{
|
||||||
|
if (importData.DoImport)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
//import this record
|
||||||
|
var Target = j.ToObject<Project>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
if (ImportProjectOverseer != -1)
|
||||||
|
Target.ProjectOverseerId = ImportProjectOverseer;
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
|
{
|
||||||
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<Project>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
if (ImportProjectOverseer != -1)
|
||||||
|
Target.ProjectOverseerId = ImportProjectOverseer;
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<Project>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
if (ImportProjectOverseer != -1)
|
|
||||||
Target.ProjectOverseerId = ImportProjectOverseer;
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -351,48 +351,55 @@ namespace AyaNova.Biz
|
|||||||
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
long existingId = await ct.ServiceRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
try
|
||||||
if (existingId == 0)
|
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
long existingId = await ct.ServiceRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (existingId == 0)
|
||||||
{
|
{
|
||||||
//import this record
|
if (importData.DoImport)
|
||||||
var Target = j.ToObject<ServiceRate>(jsset);
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//import this record
|
||||||
this.ClearErrors();
|
var Target = j.ToObject<ServiceRate>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<ServiceRate>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<ServiceRate>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
|
|||||||
@@ -329,10 +329,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
public async Task<List<string>> ImportData(AyImportData importData)
|
public async Task<List<string>> ImportData(AyImportData importData)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<string> ImportResult = new List<string>();
|
List<string> ImportResult = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
string ImportTag = ImportUtil.GetImportTag();
|
string ImportTag = ImportUtil.GetImportTag();
|
||||||
|
|
||||||
//ignore these fields
|
//ignore these fields
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ namespace AyaNova.Biz
|
|||||||
var batchResults = await ct.TravelRate.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
var batchResults = await ct.TravelRate.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
||||||
//order the results back into original
|
//order the results back into original
|
||||||
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||||
batchResults=null;
|
batchResults = null;
|
||||||
foreach (TravelRate w in orderedList)
|
foreach (TravelRate w in orderedList)
|
||||||
{
|
{
|
||||||
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
@@ -319,7 +319,7 @@ namespace AyaNova.Biz
|
|||||||
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
||||||
ReportData.Add(jo);
|
ReportData.Add(jo);
|
||||||
}
|
}
|
||||||
orderedList=null;
|
orderedList = null;
|
||||||
}
|
}
|
||||||
return ReportData;
|
return ReportData;
|
||||||
}
|
}
|
||||||
@@ -348,48 +348,55 @@ namespace AyaNova.Biz
|
|||||||
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
foreach (JObject j in importData.Data)
|
foreach (JObject j in importData.Data)
|
||||||
{
|
{
|
||||||
long existingId = await ct.TravelRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
try
|
||||||
if (existingId == 0)
|
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
long existingId = await ct.TravelRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (existingId == 0)
|
||||||
{
|
{
|
||||||
//import this record
|
if (importData.DoImport)
|
||||||
var Target = j.ToObject<TravelRate>(jsset);
|
|
||||||
Target.Tags.Add(ImportTag);
|
|
||||||
var res = await CreateAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
//import this record
|
||||||
this.ClearErrors();
|
var Target = j.ToObject<TravelRate>(jsset);
|
||||||
|
Target.Tags.Add(ImportTag);
|
||||||
|
var res = await CreateAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (importData.DoUpdate)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
//update this record with any data provided
|
||||||
|
//load existing record
|
||||||
|
var Target = await GetAsync((long)existingId);
|
||||||
|
var Source = j.ToObject<TravelRate>(jsset);
|
||||||
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
|
propertiesToUpdate.Remove("Name");
|
||||||
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
|
this.ClearErrors();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (importData.DoUpdate)
|
ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}");
|
||||||
{
|
|
||||||
//update this record with any data provided
|
|
||||||
//load existing record
|
|
||||||
var Target = await GetAsync((long)existingId);
|
|
||||||
var Source = j.ToObject<TravelRate>(jsset);
|
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
|
||||||
propertiesToUpdate.Remove("Name");
|
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
|
||||||
var res = await PutAsync(Target);
|
|
||||||
if (res == null)
|
|
||||||
{
|
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
|
||||||
this.ClearErrors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
@@ -489,7 +496,7 @@ namespace AyaNova.Biz
|
|||||||
public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null)
|
public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null)
|
||||||
{
|
{
|
||||||
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<TravelRateBiz>();
|
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<TravelRateBiz>();
|
||||||
if(ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return;
|
if (ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return;
|
||||||
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{this.BizType}, AyaEvent:{ayaEvent}]");
|
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{this.BizType}, AyaEvent:{ayaEvent}]");
|
||||||
|
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|||||||
Reference in New Issue
Block a user