This commit is contained in:
@@ -43,7 +43,7 @@ namespace AyaNova.Api.Controllers
|
||||
/// Upload and import file
|
||||
/// Max 100mb total
|
||||
/// </summary>
|
||||
/// <returns>Accepted</returns>
|
||||
/// <returns>Results</returns>
|
||||
[Authorize]
|
||||
[HttpPost("upload")]
|
||||
[DisableFormValueModelBinding]
|
||||
@@ -58,6 +58,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
// AyaTypeId attachToObject = null;
|
||||
ApiUploadProcessor.ApiUploadedFilesResult uploadFormData = null;
|
||||
List<string> ImportResult=new List<string>();
|
||||
try
|
||||
{
|
||||
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
||||
@@ -103,7 +104,7 @@ namespace AyaNova.Api.Controllers
|
||||
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
|
||||
{
|
||||
JArray ja = JArray.Parse(System.IO.File.ReadAllText(a.InitialUploadedPathName));
|
||||
await ((IImportAbleObject)biz).ImportData(ja);
|
||||
ImportResult.AddRange(await ((IImportAbleObject)biz).ImportData(ja));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +120,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//TODO: Return results of operation here
|
||||
return Accepted();
|
||||
return Ok(ImportResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for biz objects that support importing from JSON
|
||||
/// </summary>
|
||||
internal interface IImportAbleObject
|
||||
{
|
||||
Task ImportData(JArray ja);
|
||||
{
|
||||
Task<List<string>> ImportData(JArray ja);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,8 @@ using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -332,13 +334,25 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
public async Task ImportData(JArray ja)
|
||||
public async Task<List<string>> ImportData(JArray ja)
|
||||
{
|
||||
List<string> ImportResult = new List<string>();
|
||||
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<Widget>();
|
||||
await CreateAsync(w);
|
||||
var w = j.ToObject<Widget>(jsset);
|
||||
var res = await CreateAsync(w);
|
||||
if (res == null)
|
||||
{
|
||||
ImportResult.Add($"{w.Name} - no {this.GetErrorsAsString()}");
|
||||
this.ClearErrors();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImportResult.Add($"{w.Name} - ok");
|
||||
}
|
||||
}
|
||||
return ImportResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user