Last active
August 29, 2015 14:21
-
-
Save torleifhalseth/e9e76544cd2e0a7c1f37 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collections.Generic; | |
using System.Linq; | |
using MyProject.Models; | |
using Our.Umbraco.Ditto; | |
using Umbraco.Web; | |
using Umbraco.Web.WebApi; | |
namespace MyProject.Controllers.WebApi | |
{ | |
public class FeaturedArticlesController : UmbracoApiController | |
{ | |
public IEnumerable<ArticleModel> Get() | |
{ | |
//Get Root | |
var rootNode = Umbraco.TypedContentAtRoot().FirstOrDefault(node => node.DocumentTypeAlias == "Root"); | |
if (rootNode == null) return null; | |
//Get all articles | |
var articles = rootNode.Descendants().Where( | |
x => x.DocumentTypeAlias.Equals("Article") && | |
x.IsVisible() && x.TemplateId > 0).ToList(); | |
if (!articles.Any()) return null; | |
var result = articles.Select(x => x.As<ArticleModel>()); | |
var list = new List<ArticleModel>(); | |
foreach (var publishedContent in articles) | |
{ | |
var article = publishedContent.As<ArticleModel>(); | |
list.Add(article); | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment