From f606204f61733d84ced0e1d2395e0b17c1e8bed8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 8 Dec 2020 19:16:51 +0000 Subject: [PATCH] --- server/AyaNova/biz/UserBiz.cs | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index dad55adf..e2a98ef2 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -9,12 +9,14 @@ using System; using Newtonsoft.Json.Linq; using System.Collections.Generic; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + namespace AyaNova.Biz { - internal class UserBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject//, IExportAbleObject, IImportAbleObject + internal class UserBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, IImportAbleObject { @@ -761,6 +763,48 @@ namespace AyaNova.Biz } + + //////////////////////////////////////////////////////////////////////////////////////////////// + // IMPORT EXPORT + // + + + public async Task GetExportData(long[] idList) + { + //for now just re-use the report data code + //this may turn out to be the pattern for most biz object types but keeping it seperate allows for custom usage from time to time + return await GetReportData(idList); + } + + + + + public async Task> ImportData(JArray ja) + { + List ImportResult = new List(); + string ImportTag = $"imported-{FileUtil.GetSafeDateFileName()}"; + + var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) }); + foreach (JObject j in ja) + { + var w = j.ToObject(jsset); + if (j["CustomFields"] != null) + w.CustomFields = j["CustomFields"].ToString(); + w.Tags.Add(ImportTag);//so user can find them all and revert later if necessary + var res = await CreateAsync(w); + if (res == null) + { + ImportResult.Add($"* {w.Name} - {this.GetErrorsAsString()}"); + this.ClearErrors(); + } + else + { + ImportResult.Add($"{w.Name} - ok"); + } + } + return ImportResult; + } + //////////////////////////////////////////////////////////////////////////////////////////////// // JOB / OPERATIONS //