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-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>
2012-10-02 01:36:42 +05:00
/// <param name="publishedContent"></param>
2012-09-25 13:09:59 +07:00
/// <returns></returns>
2012-10-02 01:36:42 +05:00
protected RedirectToUmbracoPageResult RedirectToUmbracoPage ( IPublishedContent publishedContent )
2012-09-25 13:09:59 +07:00
{
2012-10-02 01:36:42 +05:00
return new RedirectToUmbracoPageResult ( publishedContent , UmbracoContext ) ;
2012-09-25 13:09:59 +07:00
}
/// <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>
2012-10-02 01:35:39 +05:00
protected IPublishedContent CurrentPage
2012-09-25 13:09:59 +07:00
{
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" ] ;
2012-10-02 01:40:19 +05:00
return routeDef . PublishedContentRequest . PublishedContent ;
2012-09-25 13:09:59 +07:00
}
}
2012-09-26 11:04:07 +07:00
2012-09-25 13:09:59 +07:00
}
}