This commit is contained in:
2022-03-25 19:32:32 +00:00
parent e3848306f1
commit c5222bb9d2
2 changed files with 19 additions and 25 deletions

View File

@@ -428,7 +428,7 @@ namespace AyaNova.Biz
public async Task<List<string>> ImportData(AyImportData importData)
{
List<string> ImportResult = new List<string>();
string ImportTag = $"imported-{FileUtil.GetSafeDateFileName()}";
string ImportTag = ImportUtil.GetImportTag();
//ignore these fields
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
@@ -456,24 +456,21 @@ namespace AyaNova.Biz
o.HeadOfficeId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["HeadOfficeViz"]).Select(x => x.Id).FirstOrDefaultAsync();
if (o.HeadOfficeId == 0)
AddError(ApiErrorCode.NOT_FOUND, "HeadOfficeViz", $"'{(string)j["HeadOfficeViz"]}'");
}
}
if (j["ContractViz"] != null)
{
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 (j["ContractExpires"] != null)
o.ContractExpires = (DateTime)j["ContractExpires"];
else
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
}
/*
"BillHeadOffice",
"HeadOfficeName",
"HeadOfficeViz",
"TechNotes",
"AccountNumber",
"ContractName",
"ContractViz",
"ContractExpires",
*/
var res = await CreateAsync(o);
if (res == null)
{
@@ -485,7 +482,6 @@ namespace AyaNova.Biz
ImportResult.Add($"✔️ {o.Name}");
}
}
}
else
{
@@ -497,7 +493,7 @@ namespace AyaNova.Biz
var source = j.ToObject<Customer>(jsset);
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
propertiesToUpdate.Remove("Name");
ImportUpdateObject.Update(source, target, propertiesToUpdate);
ImportUtil.Update(source, target, propertiesToUpdate);
var res = await PutAsync(target);
if (res == null)
@@ -509,15 +505,8 @@ namespace AyaNova.Biz
{
ImportResult.Add($"✔️ {target.Name}");
}
// bool copyTags=false;
// if(propertiesToUpdate.Contains("Tags"))
// copyTags=true;
}
}
}
return ImportResult;
}

View File

@@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace AyaNova.Util
{
internal static class ImportUpdateObject
internal static class ImportUtil
{
/// <summary>
/// Copies the data of one object to another. The target object 'pulls' properties of the first.
@@ -20,7 +20,7 @@ namespace AyaNova.Util
/// <param name="propertiesToUpdate">A list of properties that should be copied</param>
public static void Update(object source, object target, List<string> propertiesToUpdate)
{
MemberInfo[] miT = target.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
foreach (MemberInfo Field in miT)
{
@@ -55,6 +55,11 @@ namespace AyaNova.Util
}
public static string GetImportTag()
{
return "z-import-" + DateTime.Now.ToString("yyyyMMddHHmmss");
}
}//eoc
}//eons