Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Composite c1 - How to display data reference data in Razor functions

$
0
0
Yes, the same functionality but hell-of-a-lot shorter
ConnectedCubeCategory GetIndustry(Guid industry)
{
    return Data.Get<ConnectedCubeCategory>().FirstOrDefault(x => x.Id == industry);
}

ConnectedCubeCountry GetIndustry(Guid country)
{
    return Data.Get<ConnectedCubeCountry>().FirstOrDefault(x => x.Id == country);
}
And if you went one step further and refactored the Id property into a seperate interface both ConnectedCubeCategory and ConnectedCubeCountry implemented you could to this
T GetReferencedObject<T>(Guid id) : where T is IInterfaceWithId
{
    return Data.Get<T>().FirstOrDefault(x => x.Id == id);
}

<div class="float-left column2"> <strong>Country:</strong> @GetReferencedObject<ConnectedCubeCountry>(candidate.Country).Name </div>

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>