diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index 3a757fab..8afb52e7 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -428,7 +428,7 @@ namespace AyaNova.Biz public async Task> ImportData(AyImportData importData) { List ImportResult = new List(); - 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(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; } diff --git a/server/AyaNova/util/ImportUpdateObject.cs b/server/AyaNova/util/ImportUtil.cs similarity index 90% rename from server/AyaNova/util/ImportUpdateObject.cs rename to server/AyaNova/util/ImportUtil.cs index 236e59a1..e847631f 100644 --- a/server/AyaNova/util/ImportUpdateObject.cs +++ b/server/AyaNova/util/ImportUtil.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace AyaNova.Util { - internal static class ImportUpdateObject + internal static class ImportUtil { /// /// Copies the data of one object to another. The target object 'pulls' properties of the first. @@ -20,7 +20,7 @@ namespace AyaNova.Util /// A list of properties that should be copied public static void Update(object source, object target, List 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 \ No newline at end of file