80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
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.Helpers;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Proc.Excel;
|
|
using Saxonite.Net.Core.Web.Admin.Consoles;
|
|
using Saxonite.Net.Core.Web.Admin.Models;
|
|
using Saxonite.Net.Core.Web.Admin.Procs;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
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.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Controller: Organisation - Download
|
|
//=======================================================================
|
|
partial class OrganisationController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Download Organisations.
|
|
//-------------------------------------------------------------------
|
|
[HttpPost]
|
|
[Route("Organisation/Download")]
|
|
public IActionResult Ajax_DownloadOrganisations(Model_OrganisationDownload model)
|
|
{
|
|
String fn = GetType().Name + ".Ajax_DownloadOrganisations";
|
|
|
|
// Validate session.
|
|
if (!ValidUserSession)
|
|
return Unauthorized();
|
|
|
|
// Record disposable items as they are created so all can be disposed when needed.
|
|
using (DisposableCollection<IDisposable> disposableItems = new DisposableCollection<IDisposable>())
|
|
{
|
|
|
|
// Validate supplied data properties.
|
|
if (!model.ValidateProperties())
|
|
return BadRequest();
|
|
|
|
// Export data.
|
|
SaxOrganisationExporter.Config exporterConfig = new SaxOrganisationExporter.Config(SessionContext, DbUpdateInfo, GetOrganisationListFilter(model, AccountMgr));
|
|
exporterConfig.Format = SaxOrganisationExporter.ExportFormat.Excel_Open;
|
|
exporterConfig.IncludeId = StringUtil.ToBool(model.IncludeId);
|
|
SaxOrganisationExporter exporter = new SaxOrganisationExporter(exporterConfig);
|
|
if (exporter.RunProcess())
|
|
{
|
|
// Organisations exported successfully.
|
|
byte[] data = exporter.GetDocumentData();
|
|
using (MemoryStream content = new MemoryStream(data))
|
|
{
|
|
String contentType = exporter.GetContentType();
|
|
var fileName = "Sportierre-Organisations-" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";
|
|
return File(content.ToArray(), contentType, fileName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Problems occurred.
|
|
}
|
|
}
|
|
return NoContent();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|