Files
LeafWeb/WebCms/Controllers/ControllerBase.cs
T
poprhythm eeacfebec9 Add Hangfire
Adjust namespace
2016-11-17 13:36:13 -05:00

70 lines
1.7 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using log4net;
using LeafWeb.Core.DAL;
using Umbraco.Web.Mvc;
namespace LeafWeb.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");
}
}
}