-
-
Save jbreuer/a396f1e4504e181e1c8a to your computer and use it in GitHub Desktop.
/// <summary> | |
/// Return the all the data required for filtering and displaying object types. | |
/// </summary> | |
/// <returns></returns> | |
public static IEnumerable<ObjectTypeItem> GetObjectTypeItems() | |
{ | |
//Get the node where all projects and object types are below. | |
var projectOverview = Umbraco.TypedContent(ConfigurationManager.AppSettings["projectOverviewId"]); | |
return | |
( | |
from project in projectOverview.Children<ProjectDetails>() | |
from objectType in project.Children<ObjectTypeDetails>() | |
let city = project.City | |
select new ObjectTypeItem() | |
{ | |
ObjectType = objectType.DocumentTypeAlias.EnumParse<ObjectType>(true), | |
ProjectStatus = project.Status, | |
ObjectTypeTitle = objectType.Title, | |
ProjectTitle = project.Title, | |
CityTitle = city.Title, | |
FromPrice = objectType.FromPrice, | |
FromPriceExtra = objectType.FromPriceExtra, | |
TillPrice = objectType.TillPrice, | |
TillPriceExtra = objectType.TillPriceExtra, | |
NumberAvailable = objectType.NumberAvailable, | |
Location = project.Location, | |
Images = objectType.HeaderVisuals, | |
Url = objectType.Url | |
} | |
).ToList(); | |
} |
The EnumParse method is an extension method in the Umbraco source. You can use it if you add the Umbraco.Core namespace.
Yep, ditto is what we're using too - just makes sense.
Soooooo..... this is a static method. In this static method you are accessing an UmbracoHelper
, therefore this means that your UmracoHelper
is also static = very bad! :)
I wish everyone would please stop making static anythings unless it really makes sense. UmbracoHelper is a REQUEST based object because it relies on an UmbracoContext which is also a REQUEST based object. Anything static instantly has a SINGLETON/APPLICATION life span and thus never gets disposed.
@Shazwazza What if it was instantiated inside the static method? I mean, I use static methods all the time but I'm doing something like this:
var h = ContentHelper.GetHelper();
And this one is a method that @Nicholas-Westby was so kind to share with me - you can find it here: https://github.com/rhythmagency/rhythm.umbraco.extensions/blob/56a328f8c84d4f155d7201494be62ecfb0aaf32e/trunk/Rhythm.Extensions/Rhythm.Extensions/Helpers/ContentHelper.cs#L27 - it ensures that only one UmbracoHelper gets instantiated per HTTP request. But, even without that, why ditch statics all together and not just instantiate an UmbracoHelper?
It's great isn't it? So much cleaner IMO.
That
EnumParse<T>
method looks interesting. I'd like to see the code behind that.I've been using a custom tool based heavily on Lee Kelleher's Ditto but with a lot of performance improvements and enhancements. I can get it to automatically parse classes like this.
Note the
CarouselPane
type in the enumerable. It's able to recognise a typeconverter attribute attached to the type parameter and tell it what to do.I'm slowly but surely getting Lee to accept pull requests to add some of the improvements to Ditto so we can all use it.