Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Davide Oliva 35 posts 199 karma points
    Nov 16, 2012 @ 17:21
    Davide Oliva
    0

    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!

      @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>                                                                 
           }
      }
  • Davide Oliva 35 posts 199 karma points
    Nov 16, 2012 @ 17:26
    Davide Oliva
    0

    Sorry, I forgot to write that I'm using Umbraco v4.7.2

  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Nov 16, 2012 @ 20:05
    Jeremy Pyne
    0

    With a bit of LINQ love:

    foreach(Member member in appartiene.Select(relation
    => new Member(relation.Child.Id)).OrderBy(member => member.getProperty("gruppoAppartenenza").Value.ToString())

     

  • Davide Oliva 35 posts 199 karma points
    Nov 16, 2012 @ 22:14
    Davide Oliva
    0

    Thank you very much, Jeremy! It works smoothly! :)

  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Nov 16, 2012 @ 22:46
    Jeremy Pyne
    0

    LINQ is like cheating at programming. :O

     

    See http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies