This commit is contained in:
@@ -428,7 +428,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 = $"imported-{FileUtil.GetSafeDateFileName()}";
|
string ImportTag = ImportUtil.GetImportTag();
|
||||||
|
|
||||||
//ignore these fields
|
//ignore these fields
|
||||||
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" }) });
|
||||||
@@ -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();
|
o.HeadOfficeId = await ct.HeadOffice.AsNoTracking().Where(z => z.Name == (string)j["HeadOfficeViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
if (o.HeadOfficeId == 0)
|
if (o.HeadOfficeId == 0)
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "HeadOfficeViz", $"'{(string)j["HeadOfficeViz"]}'");
|
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);
|
var res = await CreateAsync(o);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
@@ -485,7 +482,6 @@ namespace AyaNova.Biz
|
|||||||
ImportResult.Add($"✔️ {o.Name}");
|
ImportResult.Add($"✔️ {o.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -497,7 +493,7 @@ namespace AyaNova.Biz
|
|||||||
var source = j.ToObject<Customer>(jsset);
|
var source = j.ToObject<Customer>(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");
|
||||||
ImportUpdateObject.Update(source, target, propertiesToUpdate);
|
ImportUtil.Update(source, target, propertiesToUpdate);
|
||||||
var res = await PutAsync(target);
|
var res = await PutAsync(target);
|
||||||
|
|
||||||
if (res == null)
|
if (res == null)
|
||||||
@@ -509,15 +505,8 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {target.Name}");
|
ImportResult.Add($"✔️ {target.Name}");
|
||||||
}
|
}
|
||||||
// bool copyTags=false;
|
|
||||||
// if(propertiesToUpdate.Contains("Tags"))
|
|
||||||
// copyTags=true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
namespace AyaNova.Util
|
namespace AyaNova.Util
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static class ImportUpdateObject
|
internal static class ImportUtil
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the data of one object to another. The target object 'pulls' properties of the first.
|
/// 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>
|
/// <param name="propertiesToUpdate">A list of properties that should be copied</param>
|
||||||
public static void Update(object source, object target, List<string> propertiesToUpdate)
|
public static void Update(object source, object target, List<string> propertiesToUpdate)
|
||||||
{
|
{
|
||||||
|
|
||||||
MemberInfo[] miT = target.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
|
MemberInfo[] miT = target.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
|
||||||
foreach (MemberInfo Field in miT)
|
foreach (MemberInfo Field in miT)
|
||||||
{
|
{
|
||||||
@@ -55,6 +55,11 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static string GetImportTag()
|
||||||
|
{
|
||||||
|
return "z-import-" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||||
|
}
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|
||||||
}//eons
|
}//eons
|
||||||
Reference in New Issue
Block a user