This commit is contained in:
@@ -5,7 +5,7 @@ Import / export features
|
|||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
OUTSTANDING FOR IMPORT:
|
OUTSTANDING FOR IMPORT:
|
||||||
INVENTORY
|
|
||||||
HeadOffice contract code sb more like unit contract code with null vs empty handling of json
|
HeadOffice contract code sb more like unit contract code with null vs empty handling of json
|
||||||
CustomerBiz contract code sb mroe like unit contract and updateable (update docs too to show it can be updated currently says no)
|
CustomerBiz contract code sb mroe like unit contract and updateable (update docs too to show it can be updated currently says no)
|
||||||
test each object
|
test each object
|
||||||
|
|||||||
@@ -437,6 +437,36 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
long? ImportContractId = -1;
|
||||||
|
DateTime? ImportContractExpires = null;
|
||||||
|
if (j["ContractViz"] != null)
|
||||||
|
{
|
||||||
|
ImportContractId = null;
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
||||||
|
{
|
||||||
|
ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportContractId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
||||||
|
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
||||||
|
ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
||||||
|
else
|
||||||
|
ImportContractExpires = (DateTime)j["ContractExpires"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long? ImportHeadOfficeId = -1;
|
||||||
|
if (j["HeadOfficeViz"] != null)
|
||||||
|
{
|
||||||
|
ImportHeadOfficeId = null;
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["HeadOfficeViz"]))
|
||||||
|
{
|
||||||
|
ImportHeadOfficeId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["HeadOfficeViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportHeadOfficeId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "HeadOfficeViz", $"'{(string)j["HeadOfficeViz"]}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
long existingId = await ct.Customer.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (existingId == 0)
|
if (existingId == 0)
|
||||||
@@ -447,31 +477,21 @@ namespace AyaNova.Biz
|
|||||||
var Target = j.ToObject<Customer>(jsset);
|
var Target = j.ToObject<Customer>(jsset);
|
||||||
Target.Tags.Add(ImportTag);
|
Target.Tags.Add(ImportTag);
|
||||||
|
|
||||||
|
if (ImportContractId != -1)
|
||||||
|
{
|
||||||
|
Target.ContractId = ImportContractId;
|
||||||
|
Target.ContractExpires = ImportContractExpires;
|
||||||
|
}
|
||||||
|
|
||||||
//Set linked objects
|
//Set linked objects
|
||||||
if (Target.BillHeadOffice)
|
if (Target.BillHeadOffice)
|
||||||
{
|
{
|
||||||
if (JsonUtil.JTokenIsNullOrEmpty(j["HeadOfficeViz"]))
|
if (ImportHeadOfficeId != -1)
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz");
|
Target.HeadOfficeId = ImportHeadOfficeId;
|
||||||
else
|
else
|
||||||
{
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz", "(BillHeadOffice=true)");
|
||||||
//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);
|
var res = await CreateAsync(Target);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
@@ -496,6 +516,20 @@ namespace AyaNova.Biz
|
|||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
propertiesToUpdate.Remove("Name");
|
propertiesToUpdate.Remove("Name");
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
|
if (ImportContractId != -1)
|
||||||
|
{
|
||||||
|
Target.ContractId = ImportContractId;
|
||||||
|
Target.ContractExpires = ImportContractExpires;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Target.BillHeadOffice)
|
||||||
|
{
|
||||||
|
if (ImportHeadOfficeId != -1)
|
||||||
|
Target.HeadOfficeId = ImportHeadOfficeId;
|
||||||
|
else
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeViz", "(BillHeadOffice=true)");
|
||||||
|
}
|
||||||
|
|
||||||
var res = await PutAsync(Target);
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
if (res == null)
|
if (res == null)
|
||||||
|
|||||||
@@ -355,6 +355,24 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
long? ImportContractId = -1;
|
||||||
|
DateTime? ImportContractExpires = null;
|
||||||
|
if (j["ContractViz"] != null)
|
||||||
|
{
|
||||||
|
ImportContractId = null;
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
||||||
|
{
|
||||||
|
ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
if (ImportContractId == 0)
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
||||||
|
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
||||||
|
ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
||||||
|
else
|
||||||
|
ImportContractExpires = (DateTime)j["ContractExpires"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
long existingId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
long existingId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (existingId == 0)
|
if (existingId == 0)
|
||||||
@@ -362,32 +380,23 @@ namespace AyaNova.Biz
|
|||||||
if (importData.DoImport)
|
if (importData.DoImport)
|
||||||
{
|
{
|
||||||
//import this record
|
//import this record
|
||||||
var o = j.ToObject<HeadOffice>(jsset);
|
var Target = j.ToObject<HeadOffice>(jsset);
|
||||||
o.Tags.Add(ImportTag);
|
Target.Tags.Add(ImportTag);
|
||||||
|
if (ImportContractId != -1)
|
||||||
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
|
||||||
{
|
{
|
||||||
o.ContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
Target.ContractId = ImportContractId;
|
||||||
if (o.ContractId == 0)
|
Target.ContractExpires = ImportContractExpires;
|
||||||
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);
|
var res = await CreateAsync(Target);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {o.Name}\r\n{this.GetErrorsAsString()}");
|
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
||||||
this.ClearErrors();
|
this.ClearErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {o.Name}");
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,21 +406,26 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
//update this record with any data provided
|
//update this record with any data provided
|
||||||
//load existing record
|
//load existing record
|
||||||
var target = await GetAsync((long)existingId);
|
var Target = await GetAsync((long)existingId);
|
||||||
var source = j.ToObject<HeadOffice>(jsset);
|
var Source = j.ToObject<HeadOffice>(jsset);
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
propertiesToUpdate.Remove("Name");
|
propertiesToUpdate.Remove("Name");
|
||||||
ImportUtil.Update(source, target, propertiesToUpdate);
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
var res = await PutAsync(target);
|
if (ImportContractId != -1)
|
||||||
|
{
|
||||||
|
Target.ContractId = ImportContractId;
|
||||||
|
Target.ContractExpires = ImportContractExpires;
|
||||||
|
}
|
||||||
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {target.Name} - {this.GetErrorsAsString()}");
|
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
||||||
this.ClearErrors();
|
this.ClearErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {target.Name}");
|
ImportResult.Add($"✔️ {Target.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user