111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.Mvc;
|
|
using LeafWeb.Core.Entities;
|
|
using LeafWeb.Core.Utility;
|
|
using LeafWeb.WebCms.Models;
|
|
using LeafWeb.WebCms.Utility;
|
|
using Umbraco.Web.Mvc;
|
|
|
|
namespace LeafWeb.WebCms.Controllers
|
|
{
|
|
public class DownloadController : BaseController
|
|
{
|
|
[ActionLog]
|
|
public ActionResult Results(string token)
|
|
{
|
|
var leafInput = DataService.GetLeafInput(token);
|
|
|
|
if (leafInput == null)
|
|
return View("DownloadNotFound");
|
|
|
|
var zip = leafInput.GetOutputFileZip(LeafOutputFileType.ToUser);
|
|
|
|
var filename = leafInput.Identifier.FilterValidFilename() + ".zip";
|
|
|
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
|
public ActionResult Input(int id)
|
|
{
|
|
return GetInputZip(id);
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
|
public ActionResult OutputToUser(int id)
|
|
{
|
|
return GetOutputZip(id, LeafOutputFileType.ToUser);
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Administrator")]
|
|
public ActionResult OutputNotToUser(int id)
|
|
{
|
|
return GetOutputZip(id, LeafOutputFileType.NotToUser);
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
|
public ActionResult OutputCleanedInput(int id)
|
|
{
|
|
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
|
public ActionResult ResultsInputZip(LeafDataQuery query)
|
|
{
|
|
return GetResults(query, LeafInput.GetInputFilesZip, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip");
|
|
}
|
|
|
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
|
public ActionResult ResultsOutputZip(LeafDataQuery query)
|
|
{
|
|
return GetResults(query, LeafInput.GetOutputFilesZip_ToUser, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Output.zip");
|
|
}
|
|
|
|
private ActionResult GetOutputZip(int id, LeafOutputFileType type)
|
|
{
|
|
var leafInput = DataService.GetLeafInput(id);
|
|
|
|
if (leafInput == null)
|
|
return View("DownloadNotFound");
|
|
|
|
var zip = leafInput.GetOutputFileZip(type);
|
|
|
|
var filename = $"{leafInput.Identifier.FilterValidFilename()}_{type}.zip";
|
|
|
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
}
|
|
|
|
private ActionResult GetInputZip(int id)
|
|
{
|
|
var leafInput = DataService.GetLeafInput(id);
|
|
|
|
if (leafInput == null)
|
|
return View("DownloadNotFound");
|
|
|
|
var zip = leafInput.GetInputFileZip();
|
|
|
|
var filename = $"{leafInput.Identifier.FilterValidFilename()}_Input.zip";
|
|
|
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
}
|
|
|
|
private ActionResult GetResults(LeafDataQuery query, Func<IEnumerable<LeafInput>, byte[]> getZip, string filename)
|
|
{
|
|
var resultItems =
|
|
DataService.GetLeafInputsOrdered();
|
|
|
|
resultItems
|
|
= QueryFilter.Search(resultItems, query, Members.GetCurrentLoginStatus()?.Email);
|
|
|
|
if (resultItems == null)
|
|
return View("DownloadNotFound");
|
|
|
|
var zip = getZip(resultItems);
|
|
|
|
//var filename = $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip";
|
|
|
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
}
|
|
}
|
|
} |