Move downloads to new controller

This commit is contained in:
2020-07-21 22:02:55 -04:00
parent 6a18b1be58
commit 25b5d8ebc6
10 changed files with 126 additions and 104 deletions
+111
View File
@@ -0,0 +1,111 @@
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 };
}
}
}
+1 -77
View File
@@ -108,83 +108,7 @@ namespace LeafWeb.WebCms.Controllers
return View(viewModel);
}
public ActionResult DownloadInput(int id)
{
return GetInputZip(id);
}
public ActionResult DownloadOutputToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.ToUser);
}
public ActionResult DownloadOutputNotToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.NotToUser);
}
public ActionResult DownloadOutputCleanedInput(int id)
{
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
}
public ActionResult DownloadResultsInputZip(LeafDataQuery query)
{
return GetResults(query, LeafInput.GetInputFilesZip, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip");
}
public ActionResult DownloadResultsOutputZip(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 };
}
[ActionLog]
[ActionLog]
public ActionResult Delete(int id)
{
var leafInput = DataService.GetLeafInput(id);
+2 -16
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using LeafWeb.Core.Entities;
@@ -71,20 +72,5 @@ namespace LeafWeb.WebCms.Controllers
select li;
return View(viewModel);
}
[ActionLog]
public ActionResult Download(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 };
}
}
}
}