Skip to content

Instantly share code, notes, and snippets.

@torleifhalseth
Last active August 29, 2015 14:21
Show Gist options
  • Save torleifhalseth/e9e76544cd2e0a7c1f37 to your computer and use it in GitHub Desktop.
Save torleifhalseth/e9e76544cd2e0a7c1f37 to your computer and use it in GitHub Desktop.
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