2012-09-25 13:09:59 +07:00
using System ;
using System.Collections.Concurrent ;
using System.Web.Mvc ;
using Umbraco.Core.Models ;
using Umbraco.Core ;
namespace Umbraco.Web.Mvc
{
2012-09-26 13:44:23 +07:00
//[PluginController("MyTestSurfaceController")]
//public class TestSurfaceController : SurfaceController
//{
// public ActionResult Index()
// {
// return View();
// //return Content("<html><body>hello</body></html>");
// }
2012-09-26 13:42:03 +07:00
2012-09-26 13:44:23 +07:00
// public ActionResult PostVals(string name)
// {
// ModelState.AddModelError("name", "bad name!");
// return CurrentUmbracoPage();
// }
//}
2012-09-26 13:42:03 +07:00
2012-09-26 13:44:23 +07:00
//public class LocalSurfaceController : SurfaceController
//{
// public ActionResult Index()
// {
// return View();
// }
2012-09-26 13:42:03 +07:00
2012-09-26 13:44:23 +07:00
// public ActionResult PostVals([Bind(Prefix = "blah")]string name)
// {
// ModelState.AddModelError("name", "you suck!");
// return this.RedirectToCurrentUmbracoPage();
// }
//}
2012-09-25 13:33:47 +07:00
2012-09-25 13:09:59 +07:00
/// <summary>
/// The base controller that all Presentation Add-in controllers should inherit from
/// </summary>
[MergeModelStateToChildAction]
2012-09-26 11:04:07 +07:00
public abstract class SurfaceController : PluginController
{
2012-09-25 13:09:59 +07:00
/// <summary>
/// Default constructor
/// </summary>
/// <param name="umbracoContext"></param>
protected SurfaceController ( UmbracoContext umbracoContext )
2012-09-26 11:04:07 +07:00
: base ( umbracoContext )
{
2012-09-25 13:09:59 +07:00
}
/// <summary>
/// Empty constructor, uses Singleton to resolve the UmbracoContext
/// </summary>
protected SurfaceController ( )
2012-09-26 11:04:07 +07:00
: base ( UmbracoContext . Current )
{
2012-09-25 13:09:59 +07:00
}
/// <summary>
/// Redirects to the Umbraco page with the given id
/// </summary>
/// <param name="pageId"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage ( int pageId )
{
return new RedirectToUmbracoPageResult ( pageId , UmbracoContext ) ;
}
/// <summary>
/// Redirects to the Umbraco page with the given id
/// </summary>
/// <param name="pageDocument"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage ( IDocument pageDocument )
{
return new RedirectToUmbracoPageResult ( pageDocument , UmbracoContext ) ;
}
/// <summary>
/// Redirects to the currently rendered Umbraco page
/// </summary>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage ( )
{
return new RedirectToUmbracoPageResult ( CurrentPage , UmbracoContext ) ;
}
/// <summary>
/// Returns the currently rendered Umbraco page
/// </summary>
/// <returns></returns>
protected UmbracoPageResult CurrentUmbracoPage ( )
{
return new UmbracoPageResult ( ) ;
}
/// <summary>
/// Gets the current page.
/// </summary>
protected IDocument CurrentPage
{
get
{
if ( ! ControllerContext . RouteData . DataTokens . ContainsKey ( "umbraco-route-def" ) )
throw new InvalidOperationException ( "Can only use " + typeof ( UmbracoPageResult ) . Name + " in the context of an Http POST when using the BeginUmbracoForm helper" ) ;
var routeDef = ( RouteDefinition ) ControllerContext . RouteData . DataTokens [ "umbraco-route-def" ] ;
return routeDef . DocumentRequest . Document ;
}
}
2012-09-26 11:04:07 +07:00
2012-09-25 13:09:59 +07:00
}
}