using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Web.Mvc; using ChadSoft; namespace ChadSoft.Web.Mvc { public abstract class ControllerBase : Controller { public const string SUCCESS_MESSAGE_KEY = "SuccessMessage"; public const string ERROR_MESSAGE_KEY = "ErrorMessage"; public static IIoCContainer IoCContainer { get; set; } private NameValueCollection _FormData; public NameValueCollection FormData { get { return _FormData ?? Request.Form; } set { _FormData = value; } } protected ActionResult Error(string message) { return Error(null, message); } protected void Error(IEnumerable errors) { var errorMessage = string.Empty; foreach (var error in errors) { errorMessage = string.Format("{0}\n{1}", errorMessage, error); } Error(errorMessage); } protected ActionResult Error(string format, params object[] args) { return Error(null, string.Format(format, args)); } protected ActionResult Error(Exception e, string message) { TempData[ERROR_MESSAGE_KEY] = message; return View("Error"); } protected void Success(string format, params object[] args) { Success(string.Format(format, args)); } protected void Success(string message) { TempData[SUCCESS_MESSAGE_KEY] = message; } protected virtual string ReadFromRequest(string key) { return BindingHelperExtensions.ReadFromRequest(this, key); } protected virtual T ReadFromRequest(string key) { return BindingHelperExtensions.ReadFromRequest(this, key); } } }