diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index 759835df..6a978c40 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -435,77 +435,84 @@ namespace AyaNova.Biz foreach (JObject j in importData.Data) { - long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - - if (existingId == 0) + try { - if (importData.DoImport) - { - //import this record - var Target = j.ToObject(jsset); - Target.Tags.Add(ImportTag); + long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - //Set linked objects - if (Target.BillHeadOffice) + if (existingId == 0) + { + if (importData.DoImport) { - if (JsonUtil.JTokenIsNullOrEmpty(j["HeadOfficeViz"])) - AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz"); + //import this record + var Target = j.ToObject(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 { - //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"]}'"); + ImportResult.Add($"✔️ {Target.Name}"); } } - 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(); - if (Target.ContractId == 0) - AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'"); + //update this record with any data provided + //load existing record + var Target = await GetAsync((long)existingId); + var Source = j.ToObject(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"])) - 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 + if (res == null) + { + ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}"); + this.ClearErrors(); + } 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 - { - ImportResult.Add($"✔️ {Target.Name}"); + { + ImportResult.Add($"✔️ {Target.Name}"); + } } } } - else + catch (Exception ex) { - if (importData.DoUpdate) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/HeadOfficeBiz.cs b/server/AyaNova/biz/HeadOfficeBiz.cs index 1b1a319c..f6161704 100644 --- a/server/AyaNova/biz/HeadOfficeBiz.cs +++ b/server/AyaNova/biz/HeadOfficeBiz.cs @@ -353,65 +353,72 @@ namespace AyaNova.Biz foreach (JObject j in importData.Data) { - long existingId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - - if (existingId == 0) + try { - 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 - var o = j.ToObject(jsset); - o.Tags.Add(ImportTag); - - - if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"])) + if (importData.DoImport) { - 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"]}'"); + //import this record + var o = j.ToObject(jsset); + 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 - 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(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) - { - ImportResult.Add($"❌ {o.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); - } - else - { - ImportResult.Add($"✔️ {o.Name}"); + if (res == null) + { + ImportResult.Add($"❌ {target.Name} - {this.GetErrorsAsString()}"); + this.ClearErrors(); + } + else + { + ImportResult.Add($"✔️ {target.Name}"); + } } } } - else + catch (Exception ex) { - if (importData.DoUpdate) - { - //update this record with any data provided - //load existing record - var target = await GetAsync((long)existingId); - var source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/PartAssemblyBiz.cs b/server/AyaNova/biz/PartAssemblyBiz.cs index 3a343bfb..b6839c84 100644 --- a/server/AyaNova/biz/PartAssemblyBiz.cs +++ b/server/AyaNova/biz/PartAssemblyBiz.cs @@ -392,94 +392,101 @@ namespace AyaNova.Biz foreach (JObject j in importData.Data) { - - //Compile Items collection if specified - var ImportPartAssemblyItems = new List(); - if (j["Items"] != null) + try { - //hydrate from collection - foreach (JToken t in j["Items"]) + + //Compile Items collection if specified + var ImportPartAssemblyItems = new List(); + 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; - //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(); - if (parsedPartId == 0) - AddError(ApiErrorCode.NOT_FOUND, "PartNameViz", $"'{(string)t["PartNameViz"]}'"); + if (!JsonUtil.JTokenIsNullOrEmpty(t["PartNameViz"]))//part name is mandatory, the quantity can be inferred + { + decimal parsedQuantity = 0; + //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(); + 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(jsset); + if (Target.Items == null) + Target.Items = new List(); + 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 { - //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 }); + ImportResult.Add($"✔️ {Target.Name}"); } } } - 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) + else { - //import this record - var Target = j.ToObject(jsset); - if (Target.Items == null) - Target.Items = new List(); - 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) + if (importData.DoUpdate) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); - } - else - { - ImportResult.Add($"✔️ {Target.Name}"); + //update this record with any data provided + //load existing record + var Target = await GetAsync((long)existingId); + var Source = j.ToObject(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}"); + } } } } - else + catch (Exception ex) { - if (importData.DoUpdate) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/PartBiz.cs b/server/AyaNova/biz/PartBiz.cs index ab19d3dc..3b9b4470 100644 --- a/server/AyaNova/biz/PartBiz.cs +++ b/server/AyaNova/biz/PartBiz.cs @@ -566,121 +566,128 @@ namespace AyaNova.Biz foreach (JObject j in importData.Data) { - - //Compile linked objects if specified - long? ImportManufacturerId = -1;//default meaning not included / don't set - if (j["ManufacturerViz"] != null) + try { - //something was specified, may be deliberate attempt to null it out so default to that - ImportManufacturerId = null; - if (!JsonUtil.JTokenIsNullOrEmpty(j["ManufacturerViz"])) + + //Compile linked objects if specified + long? ImportManufacturerId = -1;//default meaning not included / don't set + if (j["ManufacturerViz"] != null) { - //a name was specified so attempt to find it - 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"]}'"); - } - } - - 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 ImportSerials = new List(); - 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(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) + //something was specified, may be deliberate attempt to null it out so default to that + ImportManufacturerId = null; + if (!JsonUtil.JTokenIsNullOrEmpty(j["ManufacturerViz"])) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); + //a name was specified so attempt to find it + 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) - await PutSerialsAsync(res.Id, ImportSerials); - ImportResult.Add($"✔️ {Target.Name}"); + 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 ImportSerials = new List(); + 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(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(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) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/PartWarehouseBiz.cs b/server/AyaNova/biz/PartWarehouseBiz.cs index 083fbd8f..03576b09 100644 --- a/server/AyaNova/biz/PartWarehouseBiz.cs +++ b/server/AyaNova/biz/PartWarehouseBiz.cs @@ -335,48 +335,55 @@ namespace AyaNova.Biz var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) }); foreach (JObject j in importData.Data) { - long existingId = await ct.PartWarehouse.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - if (existingId == 0) + try { - 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 - var Target = j.ToObject(jsset); - Target.Tags.Add(ImportTag); - var res = await CreateAsync(Target); - if (res == null) + if (importData.DoImport) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); + //import this record + var Target = j.ToObject(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(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) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/ProjectBiz.cs b/server/AyaNova/biz/ProjectBiz.cs index 12b7c688..f80b2dc7 100644 --- a/server/AyaNova/biz/ProjectBiz.cs +++ b/server/AyaNova/biz/ProjectBiz.cs @@ -335,69 +335,76 @@ namespace AyaNova.Biz var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) }); foreach (JObject j in importData.Data) { - - //Compile linked objects if specified - long? ImportProjectOverseer = -1;//default meaning not included / don't set - if (j["ProjectOverseerViz"] != null) + try { - //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"]}'"); - } - } - - long existingId = await ct.Project.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - if (existingId == 0) - { - if (importData.DoImport) + //Compile linked objects if specified + long? ImportProjectOverseer = -1;//default meaning not included / don't set + if (j["ProjectOverseerViz"] != null) { - //import this record - var Target = j.ToObject(jsset); - Target.Tags.Add(ImportTag); - if (ImportProjectOverseer != -1) - Target.ProjectOverseerId = ImportProjectOverseer; - var res = await CreateAsync(Target); - if (res == null) + //something was specified, may be deliberate attempt to null it out so default to that + ImportProjectOverseer = null; + if (!JsonUtil.JTokenIsNullOrEmpty(j["ProjectOverseerViz"])) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); + //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"]}'"); } - 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(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(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) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/ServiceRateBiz.cs b/server/AyaNova/biz/ServiceRateBiz.cs index 0316a220..22d540c7 100644 --- a/server/AyaNova/biz/ServiceRateBiz.cs +++ b/server/AyaNova/biz/ServiceRateBiz.cs @@ -351,48 +351,55 @@ namespace AyaNova.Biz var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) }); foreach (JObject j in importData.Data) { - long existingId = await ct.ServiceRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - if (existingId == 0) + try { - 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 - var Target = j.ToObject(jsset); - Target.Tags.Add(ImportTag); - var res = await CreateAsync(Target); - if (res == null) + if (importData.DoImport) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); + //import this record + var Target = j.ToObject(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(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) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; diff --git a/server/AyaNova/biz/TaskGroupBiz.cs b/server/AyaNova/biz/TaskGroupBiz.cs index 0504eb74..cfe58d02 100644 --- a/server/AyaNova/biz/TaskGroupBiz.cs +++ b/server/AyaNova/biz/TaskGroupBiz.cs @@ -329,10 +329,7 @@ namespace AyaNova.Biz public async Task> ImportData(AyImportData importData) { - List ImportResult = new List(); - - string ImportTag = ImportUtil.GetImportTag(); //ignore these fields diff --git a/server/AyaNova/biz/TravelRateBiz.cs b/server/AyaNova/biz/TravelRateBiz.cs index e578b1cc..0b360118 100644 --- a/server/AyaNova/biz/TravelRateBiz.cs +++ b/server/AyaNova/biz/TravelRateBiz.cs @@ -310,7 +310,7 @@ namespace AyaNova.Biz var batchResults = await ct.TravelRate.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync(); //order the results back into original 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) { if (!ReportRenderManager.KeepGoing(jobId)) return null; @@ -319,7 +319,7 @@ namespace AyaNova.Biz jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]); ReportData.Add(jo); } - orderedList=null; + orderedList = null; } 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" }) }); foreach (JObject j in importData.Data) { - long existingId = await ct.TravelRate.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - if (existingId == 0) + try { - 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 - var Target = j.ToObject(jsset); - Target.Tags.Add(ImportTag); - var res = await CreateAsync(Target); - if (res == null) + if (importData.DoImport) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); - this.ClearErrors(); + //import this record + var Target = j.ToObject(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(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) - { - //update this record with any data provided - //load existing record - var Target = await GetAsync((long)existingId); - var Source = j.ToObject(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}"); - } - } + ImportResult.Add($"❌ Exception processing import\n record:{j.ToString()}\nError:{ex.Message}\nSource:{ex.Source}\nStack:{ex.StackTrace.ToString()}"); } } return ImportResult; @@ -489,7 +496,7 @@ namespace AyaNova.Biz public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null) { ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger(); - if(ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return; + if (ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return; log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{this.BizType}, AyaEvent:{ayaEvent}]"); bool isNew = currentObj == null;