Add Photosynthesis Type
This commit is contained in:
@@ -60,5 +60,15 @@ namespace LeafWeb.Core.DAL
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IQueryable<PhotosynthesisType> GetPhotosynthesisTypes()
|
||||
{
|
||||
return _db.PhotosynthesisTypes.OrderBy(pt => pt.SortOrder);
|
||||
}
|
||||
|
||||
public PhotosynthesisType GetPhotosynthesisType(string id)
|
||||
{
|
||||
return _db.PhotosynthesisTypes.Find(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace LeafWeb.Core.DAL
|
||||
|
||||
var photosynthesisTypes = new []
|
||||
{
|
||||
new PhotosynthesisType {Id = "C3_photosynthesis_leafweb", Name = "C3 Photosynthesis"},
|
||||
new PhotosynthesisType {Id = "C4_photosynthesis_leafweb", Name = "C4 Photosynthesis"},
|
||||
new PhotosynthesisType {Id = "CAM_photosynthesis_leafweb", Name = "CAM Photosynthesis"}
|
||||
new PhotosynthesisType {Id = "C3_photosynthesis_leafweb", Name = "C3 Photosynthesis", SortOrder = 1},
|
||||
new PhotosynthesisType {Id = "C4_photosynthesis_leafweb", Name = "C4 Photosynthesis", SortOrder = 2},
|
||||
new PhotosynthesisType {Id = "CAM_photosynthesis_leafweb", Name = "CAM Photosynthesis", SortOrder = 3}
|
||||
};
|
||||
|
||||
context.PhotosynthesisTypes.AddRange(photosynthesisTypes);
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace LeafWeb.Core.Models
|
||||
[Required(ErrorMessage = "")]
|
||||
public string SiteId { get; set; }
|
||||
|
||||
public virtual PhotosynthesisType Photosynthesis { get; set; }
|
||||
[Required(ErrorMessage = "PhotosynthesisType required")]
|
||||
public virtual PhotosynthesisType PhotosynthesisType { get; set; }
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[Required]
|
||||
|
||||
@@ -10,5 +10,7 @@ namespace LeafWeb.Core.Models
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,5 +44,10 @@ namespace LeafWeb.Web.Controllers
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected SelectList GetPhotosynthesisTypeSelectList()
|
||||
{
|
||||
return new SelectList(DataService.GetPhotosynthesisTypes().ToList(), "Id", "Name");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using LeafWeb.Core.Models;
|
||||
using LeafWeb.Web.Attributes;
|
||||
using LeafWeb.Web.ViewModels;
|
||||
using LeafWeb.Web.ViewModels.LeafInput;
|
||||
|
||||
namespace LeafWeb.Web.Controllers
|
||||
@@ -15,25 +16,9 @@ namespace LeafWeb.Web.Controllers
|
||||
{
|
||||
// initialize the session storage to retain SessionID between requests
|
||||
Session["placeholder"] = 0;
|
||||
return View();
|
||||
}
|
||||
|
||||
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
var directory = new DirectoryInfo(path);
|
||||
return
|
||||
!directory.Exists
|
||||
? new FileInfo[] {}
|
||||
: directory.GetFiles();
|
||||
}
|
||||
|
||||
private void DeleteBackloadDirectory(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
var directory = new DirectoryInfo(path);
|
||||
if (directory.Exists)
|
||||
directory.Delete(true);
|
||||
var viewModel = new CreateViewModel();
|
||||
HydrateCreateViewModel(viewModel);
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpParamAction]
|
||||
@@ -50,9 +35,21 @@ namespace LeafWeb.Web.Controllers
|
||||
{
|
||||
// Go to confirmation
|
||||
var confirmViewModel = new ConfirmViewModel(viewModel, files.Select(f => f.Name).ToArray());
|
||||
HydrateCreateViewModel(confirmViewModel);
|
||||
|
||||
return View("Confirm", confirmViewModel);
|
||||
}
|
||||
return View("Index");
|
||||
|
||||
HydrateCreateViewModel(viewModel);
|
||||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
private void HydrateCreateViewModel(dynamic viewModel)
|
||||
{
|
||||
if (viewModel.PhotosynthesisType == null)
|
||||
viewModel.PhotosynthesisType = new SelectListViewModel();
|
||||
if (viewModel.PhotosynthesisType.ListItems == null)
|
||||
viewModel.PhotosynthesisType.ListItems = GetPhotosynthesisTypeSelectList();
|
||||
}
|
||||
|
||||
[HttpParamAction]
|
||||
@@ -70,7 +67,7 @@ namespace LeafWeb.Web.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// convert viewModel into Model
|
||||
var leafInput = viewModel.GetFileInput();
|
||||
var leafInput = viewModel.GetFileInput(DataService);
|
||||
// load files into LeafInputFile
|
||||
leafInput.LeafInputFiles =
|
||||
(from f in files
|
||||
@@ -89,7 +86,27 @@ namespace LeafWeb.Web.Controllers
|
||||
StatusType.Success);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
HydrateCreateViewModel(viewModel);
|
||||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
var directory = new DirectoryInfo(path);
|
||||
return
|
||||
!directory.Exists
|
||||
? new FileInfo[] { }
|
||||
: directory.GetFiles();
|
||||
}
|
||||
|
||||
private void DeleteBackloadDirectory(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
var directory = new DirectoryInfo(path);
|
||||
if (directory.Exists)
|
||||
directory.Delete(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,16 @@ namespace LeafWeb.Web.ViewModels.LeafInput
|
||||
{
|
||||
private static readonly IMapper Mapper;
|
||||
|
||||
[Display(Name = "Your name")]
|
||||
public string Name { get; set; }
|
||||
[Display(Name = "Your email")]
|
||||
public string Email { get; set; }
|
||||
[Display(Name = "Data identifier")]
|
||||
public string Identifier { get; set; }
|
||||
[Display(Name = "Site Id")]
|
||||
public string SiteId { get; set; }
|
||||
[Display(Name = "Photosynthetic Pathway")]
|
||||
public SelectListViewModel PhotosynthesisType { get; set; }
|
||||
public string[] Files { get; set; }
|
||||
|
||||
static ConfirmViewModel()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using LeafWeb.Core.DAL;
|
||||
|
||||
namespace LeafWeb.Web.ViewModels.LeafInput
|
||||
{
|
||||
@@ -31,21 +32,28 @@ namespace LeafWeb.Web.ViewModels.LeafInput
|
||||
[Required(ErrorMessage = "The site's name is required")]
|
||||
public string SiteId { get; set; }
|
||||
|
||||
[Display(Name = "Photosynthetic Pathways")]
|
||||
[Required(ErrorMessage = "A photosynthesis pathway must be chosen")]
|
||||
public SelectListViewModel PhotosynthesisType { get; set; }
|
||||
|
||||
static CreateViewModel()
|
||||
{
|
||||
var config =
|
||||
new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<CreateViewModel, Core.Models.LeafInput>();
|
||||
cfg.CreateMap<CreateViewModel, Core.Models.LeafInput>()
|
||||
.ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
|
||||
});
|
||||
Mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
public Core.Models.LeafInput GetFileInput()
|
||||
public Core.Models.LeafInput GetFileInput(DataService db)
|
||||
{
|
||||
var leafInput = new Core.Models.LeafInput();
|
||||
Mapper.Map(this, leafInput);
|
||||
|
||||
leafInput.PhotosynthesisType = db.GetPhotosynthesisType(PhotosynthesisType.Selected);
|
||||
|
||||
return leafInput;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace LeafWeb.Web.ViewModels
|
||||
{
|
||||
public class SelectListViewModel
|
||||
{
|
||||
public SelectList ListItems { get; set; }
|
||||
public string Selected { get; set; }
|
||||
|
||||
public SelectListItem SelectedItem
|
||||
{
|
||||
get { return ListItems.FirstOrDefault(li => li.Value == Selected); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,16 @@
|
||||
</dl>
|
||||
@Html.HiddenFor(m => m.SiteId)
|
||||
|
||||
<dl class="dl-horizontal siteId">
|
||||
<dt class="small">
|
||||
@Html.DisplayNameFor(m => m.PhotosynthesisType)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayTextFor(m => m.PhotosynthesisType.SelectedItem.Text)
|
||||
</dd>
|
||||
</dl>
|
||||
<input type="hidden" name="PhotosynthesisType.Selected" value="@Model.PhotosynthesisType.Selected" />
|
||||
|
||||
<dl class="dl-horizontal files">
|
||||
<dt>
|
||||
Files
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
@Html.EditorFor(m => m.EmailConfirm)
|
||||
@Html.EditorFor(m => m.Identifier)
|
||||
@Html.EditorFor(m => m.SiteId)
|
||||
@Html.EditorFor(m => m.PhotosynthesisType)
|
||||
<input type="submit" id="submit-form" class="hidden" />
|
||||
}
|
||||
<!-- The file upload form used as target for the file upload widget -->
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
@model LeafWeb.Web.ViewModels.SelectListViewModel
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
}
|
||||
@{
|
||||
var prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
|
||||
ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
|
||||
|
||||
foreach (var li in Model.ListItems)
|
||||
{
|
||||
<div class="radio">
|
||||
<label class="radio">
|
||||
@Html.RadioButton(prefix + ".Selected", li.Value, li.Selected) @li.Text
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
|
||||
}
|
||||
@@ -2,14 +2,17 @@
|
||||
@model object
|
||||
@{
|
||||
Layout = null;
|
||||
var lowerPropertyName = @LeafWeb.Core.Utility.StringExtensions.LowercaseFirst(ViewData.ModelMetadata.PropertyName);
|
||||
var propertyName = ViewData.ModelMetadata.PropertyName;
|
||||
var lowerPropertyName = @LeafWeb.Core.Utility.StringExtensions.LowercaseFirst(propertyName);
|
||||
var values = ViewData.ModelMetadata.AdditionalValues;
|
||||
var units = values.ContainsKey("Units") ? (string)values["Units"] : null;
|
||||
var currency = values.ContainsKey("Currency") ? (string)values["Currency"] : null;
|
||||
var formatHint = values.ContainsKey("FormatHint") ? (string)values["FormatHint"] : null;
|
||||
var editLabel = values.ContainsKey("EditLabel") ? (bool)values["EditLabel"] : true;
|
||||
var hasError = ViewData.ModelState[propertyName] != null && ViewData.ModelState[propertyName].Errors.Any();
|
||||
var hasErrorClass = hasError ? "has-error" : string.Empty;
|
||||
}
|
||||
<div class="form-group @lowerPropertyName">
|
||||
<div class="form-group @lowerPropertyName @hasErrorClass">
|
||||
@Html.LabelForModel(new { @class = "control-label" })
|
||||
@RenderBody()
|
||||
@Html.ValidationMessage("", new { @class = "help-block"})
|
||||
|
||||
@@ -905,6 +905,7 @@
|
||||
<Compile Include="Utility\Validation.cs" />
|
||||
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
|
||||
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\web.config" />
|
||||
@@ -940,6 +941,7 @@
|
||||
<Content Include="Views\LeafInput\Confirm.cshtml" />
|
||||
<Content Include="Views\Shared\_StatusMessage.cshtml" />
|
||||
<Content Include="Views\Shared\_ValidationField.cshtml" />
|
||||
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
|
||||
Reference in New Issue
Block a user