using System;
using System.Collections.Concurrent;
using System.Web.Mvc;
using Umbraco.Core.Models;
using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
//[PluginController("MyTestSurfaceController")]
//public class TestSurfaceController : SurfaceController
//{
// public ActionResult Index()
// {
// return View();
// //return Content("
hello");
// }
// public ActionResult PostVals(string name)
// {
// ModelState.AddModelError("name", "bad name!");
// return CurrentUmbracoPage();
// }
//}
//public class LocalSurfaceController : SurfaceController
//{
// public ActionResult Index()
// {
// return View();
// }
// public ActionResult PostVals([Bind(Prefix = "blah")]string name)
// {
// ModelState.AddModelError("name", "you suck!");
// return this.RedirectToCurrentUmbracoPage();
// }
//}
///
/// The base controller that all Presentation Add-in controllers should inherit from
///
[MergeModelStateToChildAction]
public abstract class SurfaceController : PluginController
{
///
/// Default constructor
///
///
protected SurfaceController(UmbracoContext umbracoContext)
: base(umbracoContext)
{
}
///
/// Empty constructor, uses Singleton to resolve the UmbracoContext
///
protected SurfaceController()
: base(UmbracoContext.Current)
{
}
///
/// Redirects to the Umbraco page with the given id
///
///
///
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId)
{
return new RedirectToUmbracoPageResult(pageId, UmbracoContext);
}
///
/// Redirects to the Umbraco page with the given id
///
///
///
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IDocument pageDocument)
{
return new RedirectToUmbracoPageResult(pageDocument, UmbracoContext);
}
///
/// Redirects to the currently rendered Umbraco page
///
///
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage()
{
return new RedirectToUmbracoPageResult(CurrentPage, UmbracoContext);
}
///
/// Returns the currently rendered Umbraco page
///
///
protected UmbracoPageResult CurrentUmbracoPage()
{
return new UmbracoPageResult();
}
///
/// Gets the current page.
///
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;
}
}
}
}