Add LeafInput
Add EntityFramework
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user