I've a page with a razor macro in it, where i would like to display a list of members that are related with the page and this list should be sorted by a member property.
I wrote this code and works well, but I would like to obtain the list sorted by "gruppoAppartenenza" property.
how it's possible (if it is) to do that? Thanks a lot in advance. You're great!
@using umbraco.cms.businesslogic.relation; @using umbraco.cms.businesslogic.member; @using umbraco.MacroEngines; @using umbraco; @inherits umbraco.MacroEngines.DynamicNodeContext @{ RelationType appartenenza = RelationType.GetByAlias("appartenenzaIstituto"); Member member; Relation[] appartiene = Relation.GetRelations(Model.Id, appartenenza); var gruppo ="vuoto"; foreach (Relation relation in appartiene) { member = new Member(relation.Child.Id); var nome = member.getProperty("nome").Value.ToString(); var cognome = member.getProperty("cognome").Value.ToString(); var gruppoAppartenenza = member.getProperty("gruppoAppartenenza").Value.ToString(); var carica = member.getProperty("carica").Value.ToString(); var fotografia = member.getProperty("fotografia").Value.ToString(); if (gruppo != gruppoAppartenenza) { gruppo = gruppoAppartenenza; <div class="sezioneSX"> <div class="titolo">@gruppoAppartenenza</div> </div> } <div class="contenutoSX"> <p>@nome @cognome</p> <p>(... other code ..)</p> </div> } }
foreach(Member member in appartiene.Select(relation => new Member(relation.Child.Id)).OrderBy(member => member.getProperty("gruppoAppartenenza").Value.ToString())
Sorting members
Hi all!
I've a page with a razor macro in it, where i would like to display a list of members that are related with the page and this list should be sorted by a member property.
I wrote this code and works well, but I would like to obtain the list sorted by "gruppoAppartenenza" property.
how it's possible (if it is) to do that?
Thanks a lot in advance. You're great!
Sorry, I forgot to write that I'm using Umbraco v4.7.2
With a bit of LINQ love:
Thank you very much, Jeremy! It works smoothly! :)
LINQ is like cheating at programming. :O
See http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
is working on a reply...