Add download input link

This commit is contained in:
2016-06-28 20:08:09 -04:00
parent 4e42943229
commit dfe92218f4
3 changed files with 42 additions and 1 deletions
+21
View File
@@ -73,6 +73,27 @@ namespace LeafWeb.Core.Entities
}
}
/// <summary>
/// Contains all input files in a zip
/// </summary>
public byte[] GetInputFileZip()
{
using (var compressedFileStream = new MemoryStream())
{
using (var archive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create, true))
{
foreach (var inputFile in InputFiles)
{
var entry = archive.CreateEntry(inputFile.Filename);
using (var originalFileStream = new MemoryStream(inputFile.Contents))
using (var entryStream = entry.Open())
originalFileStream.CopyTo(entryStream);
}
}
return compressedFileStream.ToArray();
}
}
public int GetOutputFileSizeSum()
{
return OutputFiles.Sum(o => o.FileContents.Contents.Length);
+19
View File
@@ -28,6 +28,11 @@ namespace LeafWeb.Web.Controllers
return View(viewModel);
}
public ActionResult DownloadInput(int id)
{
return GetInputZip(id);
}
public ActionResult DownloadOutputToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.ToUser);
@@ -57,6 +62,20 @@ namespace LeafWeb.Web.Controllers
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 };
}
public ActionResult Delete(int id)
{
var leafInput = DataService.GetLeafInput(id);
+2 -1
View File
@@ -20,7 +20,8 @@
grid.Column("Total Results: " + Model.Count(), format:
@<div class="btn-group" role="group">
@Html.ActionLink("Details", "Details", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Download", "DownloadOutputToUser", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Dwnld", "DownloadOutputToUser", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Dwnld Input", "DownloadInput", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role = "button" })
@Html.ActionLink("Delete", "Delete", new { id = item.LeafInputId }, new { @class = "btn btn-default btn-xs", role="button" })
</div>)
),