v1.2.11.2
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Email;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.Consoles;
|
||||
using Saxonite.Net.Core.Web.Admin.Models;
|
||||
using Saxonite.Net.Core.Web.Admin.Procs;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Saxonite.Net.Standard.Base.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Controller: Organisation - Ajax - Upload
|
||||
//=======================================================================
|
||||
partial class OrganisationController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Organisation Uploader process info.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_OrganisationUploadInfo : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_OrganisationUploadInfo(SaxModel_Admin model) : base(model) { }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Organisation/Ajax/UploadInfo")]
|
||||
public IActionResult Ajax_OrganisationUploadInfo(SaxModel_Admin model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_OrganisationUploadInfo";
|
||||
String messageTitle = Localiser["caption.upload.organisations"];
|
||||
AjaxResponse_OrganisationUploadInfo responseData = new AjaxResponse_OrganisationUploadInfo(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Process console.
|
||||
SaxProcessConsole_Admin processConsole = GetProcessConsole_Admin(SessionContext);
|
||||
if (processConsole == null)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Check whether upload is in progress.
|
||||
if (processConsole.IsProcessing(SaxProcessConsole_Admin.ProcessType.OrganisationUpload))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.process.in.progress"]));
|
||||
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(fn + " " + exc.GetType().Name + " initialising organisation uploader.");
|
||||
return Json(responseData.SetMessage(messageTitle, exc.GetType().Name + " initialising organisation uploader."));
|
||||
}
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Upload Organisations.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_OrganisationUpload : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_OrganisationUpload(SaxModel_Admin model) : base(model) { }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Organisation/Ajax/Upload")]
|
||||
public IActionResult Ajax_UploadOrganisations(Model_OrganisationUpload model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_UploadOrganisations";
|
||||
String messageTitle = Localiser["caption.upload.organisations"];
|
||||
AjaxResponse_OrganisationUpload responseData = new AjaxResponse_OrganisationUpload(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Validate supplied data properties.
|
||||
if (!model.ValidateProperties(responseData))
|
||||
return Json(responseData);
|
||||
|
||||
// Process console.
|
||||
SaxProcessConsole_Admin processConsole = GetProcessConsole_Admin(SessionContext);
|
||||
if (processConsole == null)
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Check whether upload is in progress.
|
||||
if (processConsole.IsProcessing(SaxProcessConsole_Admin.ProcessType.OrganisationUpload))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.process.in.progress"]));
|
||||
|
||||
// Create the upload process.
|
||||
SaxOrganisationUploader.Config processConfig = new SaxOrganisationUploader.Config(SessionContext, model.OrganisationDataFile[0]);
|
||||
processConfig.SheetNameOrNumber = model.SheetNameOrNumber;
|
||||
SaxOrganisationUploader process = new SaxOrganisationUploader(processConfig);
|
||||
|
||||
// Store the process and run.
|
||||
processConsole.SetProcess(process);
|
||||
process.RunAsync();
|
||||
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(fn + " " + exc.GetType().Name + " initialising organisation uploader.");
|
||||
return Json(responseData.SetMessage(messageTitle, exc.GetType().Name + " initialising organisation uploader."));
|
||||
}
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user