private int GetNodeIdFromPath(string startNode) { if (startNode == null || string.IsNullOrWhiteSpace(startNode)) { return(-1); } var requestContext = new HttpContext(new HttpRequest("", "http://localhost/", ""), new HttpResponse(null)); var context = UmbracoContext.EnsureContext(new HttpContextWrapper(requestContext), ApplicationContext.Current); var helper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current); IEnumerable <IPublishedContent> rootItems; if (_targetType.Implements <IMediaPicker>()) { rootItems = helper.TypedMediaAtRoot(); } else if (_targetType.Implements <IDocumentPicker>()) { rootItems = helper.TypedContentAtRoot(); } else //TODO proper support for members? { //TODO this is a bit dodge and won't work for members. How do start nodes even work for member pickers? rootItems = helper.TypedContentAtRoot().Union(helper.TypedMediaAtRoot()); } var pieces = _startNodeInput.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int i = 0; if (pieces.Length == 0) { return(-1); } IPublishedContent current = rootItems.FirstOrDefault(x => x.Name == pieces[i]); i++; while (current != null && i < pieces.Length) { current = current.Children.FirstOrDefault(x => x.Name == pieces[i]); i++; } if (current == null) { return(-1); } else { return(current.Id); } }
/*Including a MVC Controller into the Umbraco routing!!! My CustomUmbracoApplication : UmbracoApplication wis replacing the UmbracoApplication in the Global.asax * so my SimpleController : Controller will be included in the Umbraco routing*/ public ActionResult Index() { //being that we are in a custom class, outside of an Umbraco controller, we have to instantiate our own Helper var umbracoHelper = new Umbraco.Web.UmbracoHelper(_umbracoContext); //On most website builds, you may only have one node as the root node //In these scenarios, you can use this snippet to get the homepage from the Umbraco Helper: var rootNodes = umbracoHelper.TypedContentAtRoot(); var homePage = rootNodes.FirstOrDefault(); var homeNodeById = rootNodes.First(x => x.Id == 1053); //If like me you're not very keen on hardcoding ID in your code, a more sage approach would be to filter by document type alias, //because in theory you should never have more than one homepage var homeNodeByAlias = rootNodes.FirstOrDefault(x => x.DocumentTypeAlias == "umbHomePage"); //@* Get the top item in the content tree, this will always be the Last ancestor found *@ //var websiteRoot = Model.AncestorsOrSelf().Last(); var documentType = homePage.GetPropertyValue <string>("documentType"); var documentTypeAlias = homePage.DocumentTypeAlias; ViewBag.Intro = homePage.GetPropertyValue <string>("intro"); ViewBag.Id = homePage.GetPropertyValue("_umb_id"); ViewBag.HomePageDocType = "test"; //Umbraco expects a model of type RenderModel var model = new RenderModel(_umbracoContext.ContentCache.GetById(1053), Thread.CurrentThread.CurrentCulture); return(View(model)); }
private int GetNodeIdFromPath(string startNode) { if (startNode == null || string.IsNullOrWhiteSpace(startNode)) { return -1; } var requestContext = new HttpContext(new HttpRequest("", "http://localhost/", ""), new HttpResponse(null)); var context = UmbracoContext.EnsureContext(new HttpContextWrapper(requestContext), ApplicationContext.Current); var helper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current); IEnumerable<IPublishedContent> rootItems; if (_targetType.Implements<IMediaPicker>()) { rootItems = helper.TypedMediaAtRoot(); } else if (_targetType.Implements<IDocumentPicker>()) { rootItems = helper.TypedContentAtRoot(); } else //TODO proper support for members? { //TODO this is a bit dodge and won't work for members. How do start nodes even work for member pickers? rootItems = helper.TypedContentAtRoot().Union(helper.TypedMediaAtRoot()); } var pieces = _startNodeInput.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int i = 0; if (pieces.Length == 0) { return -1; } IPublishedContent current = rootItems.FirstOrDefault(x => x.Name == pieces[i]); i++; while (current != null && i < pieces.Length) { current = current.Children.FirstOrDefault(x => x.Name == pieces[i]); i++; } if (current == null) { return -1; } else { return current.Id; } }
private static IPublishedContent GetGroupsRootFolder(UmbracoHelper helper) { return(helper.TypedContentAtRoot() .FirstOrDefault(x => x.DocumentTypeAlias == AppConstants.DocumentTypeAliases.PersonalisationGroupsFolder)); }
public SiteDetails GetSiteDetails() { var helper = new Umbraco.Web.UmbracoHelper(UmbracoContext.Current); var root = helper.TypedContentAtRoot().FirstOrDefault(); return new SiteDetails() { SiteName = root == null || !root.HasProperty("siteName") ? "" : root.GetProperty("siteName").Value.ToString(), SiteLogo = root == null || !root.HasProperty("siteLogo") ? "" : Umbraco.TypedMedia(root.GetProperty("siteLogo").Value.ToString()).Url }; }
public static IEnumerable<IPublishedContent> GetTrains(IPublishedContent page) { var Umbraco = new Umbraco.Web.UmbracoHelper(UmbracoContext.Current); IPublishedContent root = Umbraco.TypedContentAtRoot().FirstOrDefault(); return root.Descendants("Train"); }