Save leafinput to DB, update style for file upload
This commit is contained in:
@@ -37,5 +37,23 @@ namespace LeafWeb.Core.DAL
|
|||||||
select fs;
|
select fs;
|
||||||
}
|
}
|
||||||
#endregion
|
#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.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
@@ -21,12 +22,10 @@ namespace LeafWeb.Web.Controllers
|
|||||||
{
|
{
|
||||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||||
var directory = new DirectoryInfo(path);
|
var directory = new DirectoryInfo(path);
|
||||||
if (!directory.Exists)
|
return
|
||||||
{
|
!directory.Exists
|
||||||
return new FileInfo[] {};
|
? new FileInfo[] {}
|
||||||
}
|
: directory.GetFiles();
|
||||||
|
|
||||||
return directory.GetFiles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteBackloadDirectory(string directoryName)
|
private void DeleteBackloadDirectory(string directoryName)
|
||||||
@@ -34,10 +33,8 @@ namespace LeafWeb.Web.Controllers
|
|||||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||||
var directory = new DirectoryInfo(path);
|
var directory = new DirectoryInfo(path);
|
||||||
if (directory.Exists)
|
if (directory.Exists)
|
||||||
{
|
|
||||||
directory.Delete(true);
|
directory.Delete(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpParamAction]
|
[HttpParamAction]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -47,11 +44,9 @@ namespace LeafWeb.Web.Controllers
|
|||||||
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
var files = GetBackloadDirectoryFiles(Session.SessionID);
|
||||||
|
|
||||||
if (!files.Any())
|
if (!files.Any())
|
||||||
{
|
ModelState.AddModelError("Files", "Must select at least one file");
|
||||||
ModelState.AddModelError("", "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
|
// Go to confirmation
|
||||||
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
|
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
|
||||||
@@ -69,26 +64,27 @@ namespace LeafWeb.Web.Controllers
|
|||||||
|
|
||||||
if (!files.Any())
|
if (!files.Any())
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("", "Must select at least one file");
|
ModelState.AddModelError("Files", "Must select at least one file");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// convert viewModel into Model
|
// convert viewModel into Model
|
||||||
var model = viewModel.GetFileInput();
|
var leafInput = viewModel.GetFileInput();
|
||||||
// load files into LeafInputFile
|
// load files into LeafInputFile
|
||||||
var leafInputFiles =
|
leafInput.LeafInputFiles =
|
||||||
from f in files
|
(from f in files
|
||||||
let bytes = System.IO.File.ReadAllBytes(f.FullName)
|
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);
|
DeleteBackloadDirectory(Session.SessionID);
|
||||||
|
|
||||||
SetStatusMessage(
|
SetStatusMessage(
|
||||||
HttpUtility.HtmlEncode(
|
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."),
|
+ $"When complete, an email will be delivered to {viewModel.Name} <{viewModel.Email}> with results."),
|
||||||
StatusType.Success);
|
StatusType.Success);
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<label class="control-label">Files</label>
|
<label class="control-label">Files</label>
|
||||||
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
|
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
|
||||||
<div class="row fileupload-buttonbar">
|
<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 -->
|
<!-- The fileinput-button span is used to style the file input field as button -->
|
||||||
<span class="btn btn-default fileinput-button">
|
<span class="btn btn-default fileinput-button">
|
||||||
<i class="glyphicon glyphicon-plus"></i>
|
<i class="glyphicon glyphicon-plus"></i>
|
||||||
@@ -44,15 +44,16 @@
|
|||||||
<span class="fileupload-process"></span>
|
<span class="fileupload-process"></span>
|
||||||
</div>
|
</div>
|
||||||
<!-- The global progress state -->
|
<!-- The global progress state -->
|
||||||
<div class="col-lg-6 fileupload-progress fade">
|
<div class="col-lg-7 fileupload-progress fade">
|
||||||
<!-- The global progress bar -->
|
<!-- The global progress bar -->
|
||||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
|
<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 class="progress-bar progress-bar-success" style="width: 0%;"></div>
|
||||||
</div>
|
</div>
|
||||||
<!-- The extended global progress state -->
|
<!-- The extended global progress state -->
|
||||||
<div class="progress-extended"> </div>
|
@*<div class="progress-extended"> </div>*@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@Html.Partial("_ValidationField", "Files")
|
||||||
<!-- The table listing the files available for upload/download -->
|
<!-- The table listing the files available for upload/download -->
|
||||||
<table role="presentation" class="table table-striped panel panel-default"><tbody class="files"></tbody></table>
|
<table role="presentation" class="table table-striped panel panel-default"><tbody class="files"></tbody></table>
|
||||||
</form>
|
</form>
|
||||||
@@ -70,7 +71,8 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p class="size">Processing...</p>
|
<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>
|
||||||
<td>
|
<td>
|
||||||
{% if (!i && !o.options.autoUpload) { %}
|
{% 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="Scripts\jquery.validate.unobtrusive.bootstrap.min.js.map" />
|
||||||
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
||||||
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
||||||
|
<Content Include="Views\Shared\_ValidationField.cshtml" />
|
||||||
<None Include="Web.Debug.config">
|
<None Include="Web.Debug.config">
|
||||||
<DependentUpon>Web.config</DependentUpon>
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
Reference in New Issue
Block a user