Save leafinput to DB, update style for file upload
This commit is contained in:
@@ -37,5 +37,23 @@ namespace LeafWeb.Core.DAL
|
||||
select fs;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Fluxnet Sites
|
||||
|
||||
public IQueryable<LeafInput> GetLeafInputs()
|
||||
{
|
||||
return _db.LeafInputs;
|
||||
}
|
||||
|
||||
public void AddLeafInput(LeafInput leafInput)
|
||||
{
|
||||
leafInput.Created = DateTime.Now;
|
||||
|
||||
_db.LeafInputs.Add(leafInput);
|
||||
_db.SaveChanges();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<label class="control-label">Files</label>
|
||||
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
|
||||
<div class="row fileupload-buttonbar">
|
||||
<div class="col-lg-6">
|
||||
<div class="col-lg-5">
|
||||
<!-- The fileinput-button span is used to style the file input field as button -->
|
||||
<span class="btn btn-default fileinput-button">
|
||||
<i class="glyphicon glyphicon-plus"></i>
|
||||
@@ -44,15 +44,16 @@
|
||||
<span class="fileupload-process"></span>
|
||||
</div>
|
||||
<!-- The global progress state -->
|
||||
<div class="col-lg-6 fileupload-progress fade">
|
||||
<div class="col-lg-7 fileupload-progress fade">
|
||||
<!-- The global progress bar -->
|
||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar progress-bar-success" style="width: 0%;"></div>
|
||||
</div>
|
||||
<!-- The extended global progress state -->
|
||||
<div class="progress-extended"> </div>
|
||||
@*<div class="progress-extended"> </div>*@
|
||||
</div>
|
||||
</div>
|
||||
@Html.Partial("_ValidationField", "Files")
|
||||
<!-- The table listing the files available for upload/download -->
|
||||
<table role="presentation" class="table table-striped panel panel-default"><tbody class="files"></tbody></table>
|
||||
</form>
|
||||
@@ -70,7 +71,8 @@
|
||||
</td>
|
||||
<td>
|
||||
<p class="size">Processing...</p>
|
||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
|
||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
|
||||
<div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
|
||||
</td>
|
||||
<td>
|
||||
{% if (!i && !o.options.autoUpload) { %}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
@model string
|
||||
@{
|
||||
var fieldName = Model;
|
||||
}
|
||||
@if (ViewData.ModelState[fieldName] != null && ViewData.ModelState[fieldName].Errors.Any())
|
||||
{
|
||||
<span class="help-block field-validation-error">
|
||||
@foreach (var error in ViewData.ModelState[fieldName].Errors)
|
||||
{
|
||||
<span id="@fieldName-error" class="text-danger">@error.ErrorMessage</span>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
@@ -939,6 +939,7 @@
|
||||
<Content Include="Scripts\jquery.validate.unobtrusive.bootstrap.min.js.map" />
|
||||
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
||||
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
||||
<Content Include="Views\Shared\_ValidationField.cshtml" />
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
|
||||
Reference in New Issue
Block a user