Created
March 17, 2012 21:25
-
-
Save warrenbuckley/2065415 to your computer and use it in GitHub Desktop.
Work In Progress - JSON Content Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
//WB Added | |
using Umbraco.Cms.Web; | |
using Umbraco.Cms.Web.Context; | |
using Umbraco.Framework.Persistence.Model.Associations; | |
using Umbraco.Hive; | |
using Umbraco.Hive.RepositoryTypes; | |
using Umbraco.Cms.Web.Model; | |
using Umbraco.Framework; | |
using Umbraco.Framework.Context; | |
namespace JSONController.Controllers | |
{ | |
public class JSONController : Controller | |
{ | |
private readonly IUmbracoApplicationContext context; | |
public JSONController(IUmbracoApplicationContext context) | |
{ | |
this.context = context; | |
} | |
public JsonResult GetContentById(HiveId contentID) | |
{ | |
//Get the node | |
var node = context.Hive.Cms().Content.GetById(contentID); | |
//Return as JSON | |
return Json(node, JsonRequestBehavior.AllowGet); | |
} | |
public JsonResult GetContentByNodeName(string nodeName) | |
{ | |
var node = context.Hive.Cms().Content.SingleOrDefault(x => x.Name == nodeName); | |
//Return as JSON | |
return Json(node, JsonRequestBehavior.AllowGet); | |
} | |
public JsonResult GetContentByDocType(string doctypeAlias) | |
{ | |
var nodes = context.Hive.Cms().Content.Where(x => x.ContentType.Alias == doctypeAlias); | |
//Return as JSON | |
return Json(nodes, JsonRequestBehavior.AllowGet); | |
} | |
} | |
} |
Hi Doug,
This was very much a proof of concept and was untested.
Warren :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warren
Thanks for these. Is this JSON controler working for you in v5.1(CMS)?
Doug