using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Web.Mvc; namespace Website.Controllers { public abstract class ControllerBase : Controller { public const string SUCCESS_MESSAGE_KEY = "SuccessMessage"; public const string ERROR_MESSAGE_KEY = "ErrorMessage"; private IDictionary _TempData; public new IDictionary TempData { get { return _TempData ?? base.TempData; } internal set { _TempData = value; } } private NameValueCollection _FormData; public NameValueCollection FormData { get { return _FormData ?? Request.Form; } internal set { _FormData = value; } } protected IIoCContainer Container { get { return GlobalApplication.Container; } } 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; } } }