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