diff --git a/WebCms/App_Data/Models/all.generated.cs b/WebCms/App_Data/Models/all.generated.cs index 57cc212..6a66d9a 100644 --- a/WebCms/App_Data/Models/all.generated.cs +++ b/WebCms/App_Data/Models/all.generated.cs @@ -8,7 +8,7 @@ using Umbraco.Web; using Umbraco.ModelsBuilder; using Umbraco.ModelsBuilder.Umbraco; [assembly: PureLiveAssembly] -[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "508a57e7748cbe2")] +[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "a97af64e5fffa72c")] [assembly:System.Reflection.AssemblyVersion("0.0.0.1")] @@ -260,41 +260,6 @@ namespace Umbraco.Web.PublishedContentModels } } - /// Leaf Input - [PublishedContentModel("TextPage1")] - public partial class TextPage1 : PublishedContentModel - { -#pragma warning disable 0109 // new is redundant - public new const string ModelTypeAlias = "TextPage1"; - public new const PublishedItemType ModelItemType = PublishedItemType.Content; -#pragma warning restore 0109 - - public TextPage1(IPublishedContent content) - : base(content) - { } - -#pragma warning disable 0109 // new is redundant - public new static PublishedContentType GetModelContentType() - { - return PublishedContentType.Get(ModelItemType, ModelTypeAlias); - } -#pragma warning restore 0109 - - public static PublishedPropertyType GetModelPropertyType(Expression> selector) - { - return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector); - } - - /// - /// Content - /// - [ImplementPropertyType("content")] - public Newtonsoft.Json.Linq.JToken Content - { - get { return this.GetPropertyValue("content"); } - } - } - /// Folder [PublishedContentModel("Folder")] public partial class Folder : PublishedContentModel diff --git a/WebCms/App_Data/Models/models.generated.cs b/WebCms/App_Data/Models/models.generated.cs index a0aa3ae..1b277c5 100644 --- a/WebCms/App_Data/Models/models.generated.cs +++ b/WebCms/App_Data/Models/models.generated.cs @@ -19,7 +19,7 @@ using Umbraco.ModelsBuilder; using Umbraco.ModelsBuilder.Umbraco; [assembly: PureLiveAssembly] -[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "508a57e7748cbe2")] +[assembly:ModelsBuilderAssembly(PureLive = true, SourceHash = "a97af64e5fffa72c")] [assembly:System.Reflection.AssemblyVersion("0.0.0.2")] namespace Umbraco.Web.PublishedContentModels @@ -244,41 +244,6 @@ namespace Umbraco.Web.PublishedContentModels } } - /// Leaf Input - [PublishedContentModel("TextPage1")] - public partial class TextPage1 : PublishedContentModel - { -#pragma warning disable 0109 // new is redundant - public new const string ModelTypeAlias = "TextPage1"; - public new const PublishedItemType ModelItemType = PublishedItemType.Content; -#pragma warning restore 0109 - - public TextPage1(IPublishedContent content) - : base(content) - { } - -#pragma warning disable 0109 // new is redundant - public new static PublishedContentType GetModelContentType() - { - return PublishedContentType.Get(ModelItemType, ModelTypeAlias); - } -#pragma warning restore 0109 - - public static PublishedPropertyType GetModelPropertyType(Expression> selector) - { - return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector); - } - - /// - /// Content - /// - [ImplementPropertyType("content")] - public Newtonsoft.Json.Linq.JToken Content - { - get { return this.GetPropertyValue("content"); } - } - } - /// Folder [PublishedContentModel("Folder")] public partial class Folder : PublishedContentModel diff --git a/WebCms/App_Data/Models/models.hash b/WebCms/App_Data/Models/models.hash index 530b88b..ff11dd5 100644 --- a/WebCms/App_Data/Models/models.hash +++ b/WebCms/App_Data/Models/models.hash @@ -1 +1 @@ -508a57e7748cbe2 \ No newline at end of file +a97af64e5fffa72c \ No newline at end of file diff --git a/WebCms/App_Start/RegisterDataService.cs b/WebCms/App_Start/RegisterDataService.cs new file mode 100644 index 0000000..509f6c4 --- /dev/null +++ b/WebCms/App_Start/RegisterDataService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using LeafWeb.Core.DAL; +using Umbraco.Core; + +namespace WebCms.App_Start +{ + public class RegisterDataService : ApplicationEventHandler + { + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + DataService.RegisterInitializer(); + + base.ApplicationStarted(umbracoApplication, applicationContext); + } + } +} \ No newline at end of file diff --git a/WebCms/Controllers/ControllerBase.cs b/WebCms/Controllers/ControllerBase.cs new file mode 100644 index 0000000..40ef984 --- /dev/null +++ b/WebCms/Controllers/ControllerBase.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using System.Web.Mvc; +using log4net; +using LeafWeb.Core.DAL; +using Umbraco.Web.Mvc; + +namespace WebCms.Controllers +{ + public class BaseController : SurfaceController + { + protected readonly DataService DataService = new DataService(); + + protected override void Dispose(bool disposing) + { + DataService.Dispose(); + base.Dispose(disposing); + } + + protected override void OnException(ExceptionContext filterContext) + { + if (filterContext?.Exception != null) + { + var controller = filterContext.RouteData.Values["controller"].ToString(); + var action = filterContext.RouteData.Values["action"].ToString(); + var loggerName = $"{controller}Controller.{action}"; + + LogManager.GetLogger(loggerName).Error(filterContext.Exception); + } + + base.OnException(filterContext); + } + + protected bool IsHttpParamActionMatch() + { + return ControllerContext.RouteData.Values["action"].ToString() + .Equals("Action", StringComparison.InvariantCultureIgnoreCase); + } + + protected enum StatusType + { + Info, + Success, + Error + } + + protected void SetStatusMessage(string msg, StatusType statusType = StatusType.Info) + { + TempData["StatusMessage"] = msg; + switch (statusType) + { + case StatusType.Success: + TempData["StatusMessage-Type"] = "alert-success"; + break; + case StatusType.Error: + TempData["StatusMessage-Type"] = "alert-error"; + break; + case StatusType.Info: + break; + default: + throw new ArgumentOutOfRangeException(nameof(statusType), statusType, null); + } + } + + protected SelectList GetPhotosynthesisTypeSelectList() + { + return new SelectList(DataService.GetPhotosynthesisTypes().ToList(), "Id", "Name"); + } + } +} \ No newline at end of file diff --git a/WebCms/Controllers/LeafInputController.cs b/WebCms/Controllers/LeafInputController.cs index fcff3c9..fc4b536 100644 --- a/WebCms/Controllers/LeafInputController.cs +++ b/WebCms/Controllers/LeafInputController.cs @@ -1,13 +1,49 @@ using System.Web.Mvc; -using Umbraco.Web.Mvc; +using WebCms.Models; namespace WebCms.Controllers { - public class LeafInputController : SurfaceController + public class LeafInputController : BaseController { - public ActionResult Index() + public ActionResult Create() { - return View(); + var viewModel = new LeafInputCreate(); + HydrateCreateViewModel(viewModel); + return PartialView(viewModel); + } + + //[HttpParamAction] + [HttpPost] + public ActionResult Submit(LeafInputCreate viewModel) + { + if (!ModelState.IsValid) + return CurrentUmbracoPage(); + + // directory name is the sessionID + //var files = GetBackloadDirectoryFiles(Session.SessionID); + + //if (!files.Any()) + // ModelState.AddModelError("Files", "Must select at least one file"); + + //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()); + // HydrateCreateViewModel(confirmViewModel); + + // return View("Confirm", confirmViewModel); + //} + + HydrateCreateViewModel(viewModel); + return CurrentUmbracoPage(); + } + + private void HydrateCreateViewModel(dynamic viewModel) + { + if (viewModel.PhotosynthesisType == null) + viewModel.PhotosynthesisType = new SelectListViewModel(); + if (viewModel.PhotosynthesisType.ListItems == null) + viewModel.PhotosynthesisType.ListItems = GetPhotosynthesisTypeSelectList(); } } } \ No newline at end of file diff --git a/WebCms/Models/LeafInputConfirm.cs b/WebCms/Models/LeafInputConfirm.cs index c5a741e..c980ba3 100644 --- a/WebCms/Models/LeafInputConfirm.cs +++ b/WebCms/Models/LeafInputConfirm.cs @@ -1,5 +1,8 @@ using System.ComponentModel.DataAnnotations; +using System.Globalization; using AutoMapper; +using Umbraco.Core.Models; +using Umbraco.Web.Models; namespace WebCms.Models { @@ -22,10 +25,18 @@ namespace WebCms.Models Mapper.CreateMap(); } - public LeafInputConfirm(LeafInputCreate leafInputCreate, string[] files) - { - Mapper.Map(leafInputCreate, this); - Files = files; - } + //public LeafInputConfirm(LeafInputCreate leafInputCreate, string[] files) + //{ + // Mapper.Map(leafInputCreate, this); + // Files = files; + //} + + //public LeafInputConfirm(IPublishedContent content, CultureInfo culture) : base(content, culture) + //{ + //} + + //public LeafInputConfirm(IPublishedContent content) : base(content) + //{ + //} } } \ No newline at end of file diff --git a/WebCms/Models/LeafInputCreate.cs b/WebCms/Models/LeafInputCreate.cs index b97e587..95b4076 100644 --- a/WebCms/Models/LeafInputCreate.cs +++ b/WebCms/Models/LeafInputCreate.cs @@ -1,6 +1,9 @@ using System.ComponentModel.DataAnnotations; +using System.Globalization; using AutoMapper; using LeafWeb.Core.DAL; +using Umbraco.Core.Models; +using Umbraco.Web.Models; namespace WebCms.Models { @@ -11,24 +14,24 @@ namespace WebCms.Models [RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Please provide your full name")] public string Name { get; set; } - [Display(Name = "Your email address")] - [Required(ErrorMessage = "An email address is required")] - [DataType(DataType.EmailAddress)] - [RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")] - public string Email { get; set; } + //[Display(Name = "Your email address")] + //[Required(ErrorMessage = "An email address is required")] + //[DataType(DataType.EmailAddress)] + //[RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")] + //public string Email { get; set; } - [Display(Name = "Confirm email address")] - [Required(ErrorMessage = "Enter email exactly as above")] - [Compare("Email")] - public string EmailConfirm { get; set; } + //[Display(Name = "Confirm email address")] + //[Required(ErrorMessage = "Enter email exactly as above")] + //[Compare("Email")] + //public string EmailConfirm { get; set; } - [Display(Name = "A unique identifier for this data")] - [Required(ErrorMessage = "A unique identifier is required")] - public string Identifier { get; set; } + //[Display(Name = "A unique identifier for this data")] + //[Required(ErrorMessage = "A unique identifier is required")] + //public string Identifier { get; set; } - [Display(Name = "The site's name/Fluxnet ID, if known")] - [Required(ErrorMessage = "The site's name is required")] - public string SiteId { get; set; } + //[Display(Name = "The site's name/Fluxnet ID, if known")] + //[Required(ErrorMessage = "The site's name is required")] + //public string SiteId { get; set; } [Display(Name = "Photosynthetic Pathways")] [Required(ErrorMessage = "A Photosynthetic pathway must be chosen")] @@ -40,13 +43,16 @@ namespace WebCms.Models .ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore()); } - public LeafWeb.Core.Entities.LeafInput GetFileInput(DataService db) + public LeafInputCreate() + { + //PhotosynthesisType = new SelectListViewModel(); + } + + public LeafWeb.Core.Entities.LeafInput GetFileInput() { var leafInput = new LeafWeb.Core.Entities.LeafInput(); Mapper.Map(this, leafInput); - leafInput.PhotosynthesisType = db.GetPhotosynthesisType(PhotosynthesisType.Selected); - return leafInput; } } diff --git a/WebCms/Views/LeafInput.cshtml b/WebCms/Views/LeafInput.cshtml deleted file mode 100644 index eefc106..0000000 --- a/WebCms/Views/LeafInput.cshtml +++ /dev/null @@ -1,9 +0,0 @@ -@inherits UmbracoTemplatePage -@{ - Layout = "Master.cshtml"; -} -@CurrentPage.GetGridHtml("content", "fanoe") - -@section Form{ - @Html.Action("Index", "LeafInput") -} diff --git a/WebCms/Views/LeafInput/Index.cshtml b/WebCms/Views/LeafInput/Create.cshtml similarity index 53% rename from WebCms/Views/LeafInput/Index.cshtml rename to WebCms/Views/LeafInput/Create.cshtml index 4204436..e33ac94 100644 --- a/WebCms/Views/LeafInput/Index.cshtml +++ b/WebCms/Views/LeafInput/Create.cshtml @@ -1,51 +1,17 @@ -@inherits UmbracoViewPage +@model WebCms.Models.LeafInputCreate
@Html.Partial("_ValidationSummary") - -
- - -
-
- - - - Add files... - - - - - - -
- -
- -
-
-
- - @*
 
*@ -
-
- @Html.Partial("_ValidationField", "Files") - - -
- @using (Html.BeginForm("Index", "LeafInput", FormMethod.Post)) + @using (Html.BeginUmbracoForm("Submit", "LeafInput", FormMethod.Post)) { - //@Html.EditorFor(m => m.PhotosynthesisType) - @Html.EditorFor(m => m.Identifier) - @Html.EditorFor(m => m.SiteId) + @Html.EditorFor(m => m.PhotosynthesisType) + @*@Html.EditorFor(m => m.Identifier) + @Html.EditorFor(m => m.SiteId)*@ @Html.EditorFor(m => m.Name) - @Html.EditorFor(m => m.Email) - @Html.EditorFor(m => m.EmailConfirm) + @*@Html.EditorFor(m => m.Email) + @Html.EditorFor(m => m.EmailConfirm)*@ }
diff --git a/WebCms/Views/MacroPartials/LeafInputCreate.cshtml b/WebCms/Views/MacroPartials/LeafInputCreate.cshtml new file mode 100644 index 0000000..efc787c --- /dev/null +++ b/WebCms/Views/MacroPartials/LeafInputCreate.cshtml @@ -0,0 +1,5 @@ +@inherits Umbraco.Web.Macros.PartialViewMacroPage + +@{ + Html.RenderAction("Create", "LeafInput"); +} \ No newline at end of file diff --git a/WebCms/Web.config b/WebCms/Web.config index c8477df..584875f 100644 --- a/WebCms/Web.config +++ b/WebCms/Web.config @@ -1,78 +1,92 @@ - + -
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+ +
- - - - + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - - - + + + + - + - - - + + + - + - - - + + + - - - - - + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - + - - - + + + - - + + - + - + - - - - - - - - - + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - + - + @@ -321,85 +335,91 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + + + + + + + \ No newline at end of file diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index 18a6608..04dff6f 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -76,6 +76,14 @@ ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll True + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + ..\packages\Examine.0.1.70.0\lib\Examine.dll True @@ -337,8 +345,7 @@ - - + @@ -358,6 +365,7 @@ + Web.config @@ -398,6 +406,8 @@ + + @@ -415,6 +425,7 @@ Core + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/WebCms/packages.config b/WebCms/packages.config index 6d10b65..04bdd1c 100644 --- a/WebCms/packages.config +++ b/WebCms/packages.config @@ -3,6 +3,7 @@ +