Save leafinput to DB, update style for file upload

This commit is contained in:
2016-02-04 13:46:08 -05:00
parent 38247eb43f
commit 65bc2b98ab
5 changed files with 54 additions and 24 deletions
+16 -20
View File
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
@@ -21,12 +22,10 @@ namespace LeafWeb.Web.Controllers
{
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
var directory = new DirectoryInfo(path);
if (!directory.Exists)
{
return new FileInfo[] {};
}
return directory.GetFiles();
return
!directory.Exists
? new FileInfo[] {}
: directory.GetFiles();
}
private void DeleteBackloadDirectory(string directoryName)
@@ -34,9 +33,7 @@ namespace LeafWeb.Web.Controllers
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
var directory = new DirectoryInfo(path);
if (directory.Exists)
{
directory.Delete(true);
}
}
[HttpParamAction]
@@ -47,11 +44,9 @@ namespace LeafWeb.Web.Controllers
var files = GetBackloadDirectoryFiles(Session.SessionID);
if (!files.Any())
{
ModelState.AddModelError("", "Must select at least one file");
}
ModelState.AddModelError("Files", "Must select at least one file");
if (ModelState.IsValid && !IsHttpParamActionMatch())
if (ModelState.IsValid && !IsHttpParamActionMatch()) // HttpParamMatch indicates it's backing out from Confirm
{
// Go to confirmation
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
@@ -69,26 +64,27 @@ namespace LeafWeb.Web.Controllers
if (!files.Any())
{
ModelState.AddModelError("", "Must select at least one file");
ModelState.AddModelError("Files", "Must select at least one file");
}
if (ModelState.IsValid)
{
// convert viewModel into Model
var model = viewModel.GetFileInput();
var leafInput = viewModel.GetFileInput();
// load files into LeafInputFile
var leafInputFiles =
from f in files
leafInput.LeafInputFiles =
(from f in files
let bytes = System.IO.File.ReadAllBytes(f.FullName)
select new LeafInputFile {Filename = f.Name, Contents = bytes};
select new LeafInputFile {Filename = f.Name, Contents = bytes}).ToList();
// TODO: Save to db
// Save to db
DataService.AddLeafInput(leafInput);
DeleteBackloadDirectory(Session.SessionID);
SetStatusMessage(
HttpUtility.HtmlEncode(
$"A data set has submitted for '{viewModel.Identifier}' from '{viewModel.SiteId}'. "
$"A data set has submitted for '{viewModel.Identifier}' from '{viewModel.SiteId}'. " + Environment.NewLine
+ $"When complete, an email will be delivered to {viewModel.Name} <{viewModel.Email}> with results."),
StatusType.Success);
return RedirectToAction("Index");