﻿@using System.Dynamic;
@using System.Linq;
@using Orchard.ContentManagement;
@using Orchard.Utility.Extensions;

@functions
{
    dynamic GetMainPartFromContentItem(ContentItem item)
    {
        // get the ContentPart that has the same name as the item's ContentType
        // so that we can access the item fields.
        var contentType = item.TypeDefinition.Name;
        var parts = item.Parts as List<ContentPart>;
        return parts.First(p => p.PartDefinition.Name.Equals(contentType));  
    }
}

@{
    var contentItems = (Model.ContentItems as IEnumerable<ContentItem>);
    var cssClass = contentItems.First().TypeDefinition.Name.HtmlClassify();

    <ul>
        @foreach (ContentItem item in contentItems)
        {
            var itemDisplayUrl = Url.ItemDisplayUrl(item);
            // get the mainPart, so we can access the item's fields
            dynamic mainPart = GetMainPartFromContentItem(item);
            var firstName = mainPart.FirstName.Value;
            var lastName = mainPart.LastName.Value;
            var position = mainPart.Position.Value;
            var email = mainPart.Email.Value;
            //var associatedLcc = mainPart.
            <li>
                <p>@firstName @lastName @position</p>
            </li>
        }
    </ul>



}
﻿@using System.Dynamic;
@using System.Linq;
@using Orchard.ContentManagement;
@using Orchard.Utility.Extensions;

@functions
{
    dynamic GetMainPartFromContentItem(ContentItem item)
    {
        // get the ContentPart that has the same name as the item's ContentType
        // so that we can access the item fields.
        var contentType = item.TypeDefinition.Name;
        var parts = item.Parts as List<ContentPart>;
        return parts.First(p => p.PartDefinition.Name.Equals(contentType));  
    }

    dynamic GetTermPartFromTaxonomyField(dynamic field, int index = 0)
    {
        // get the termPart at index in the taxonomy field
        return field !=null &&
            field.Terms != null &&
            field.Terms.Count > index ? 
            field.Terms[index] : null;
    }
}

@{
    var contentItems = (Model.ContentItems as IEnumerable<ContentItem>);
    var cssClass = contentItems.First().TypeDefinition.Name.HtmlClassify();

    <ul>
        @foreach (ContentItem item in contentItems)
        {
            var itemDisplayUrl = Url.ItemDisplayUrl(item);
            // get the mainPart, so we can access the item's fields
            dynamic mainPart = GetMainPartFromContentItem(item);
            var firstName = mainPart.FirstName.Value;
            var lastName = mainPart.LastName.Value;
            var position = mainPart.Position.Value;
            var email = mainPart.Email.Value;
            var lccTermPart = GetTermPartFromTaxonomyField(mainPart.Lcc);
            var associatedLcc = lccTermPart != null ? lccTermPart.Name : string.Empty;
            <li>
                <p>@firstName @lastName @position @email @associatedLcc</p>
            </li>
        }
    </ul>



}
Tweak the latest news view.
Tweak the latest news view.
