Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Dec 04, 2014 @ 12:06
    Daniel Larsen
    0

    List member properties and group names

    Hi,

    I have a member page, where I show the members with their properties like name, birthday and so.

    Now I would like to show which groups the different members are part of. How do I do that? Is there a special property i can retrieve?

    Thanks for your help! :-)

    /Daniel

    u7

  • Dan Lister 416 posts 1973 karma points c-trib
    Dec 04, 2014 @ 12:16
    Dan Lister
    1

    Hi Daniel,

    For each member displayed on the page, you should be able to use the following method to retrieve a list of groups the member is a part of:

    string[] groups = Roles.GetRolesForUser(member.Username);
    

    Hope that helps.

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Dec 04, 2014 @ 12:38
    Daniel Larsen
    0

    Thanks Dan!

    I hope you will help me a bit more.

    I have this code, but I am doing it wrong.

    @{
        var y = Member.GetAll; 
        foreach (var item in y) {
           string[] groups = Roles.GetRolesForUser(member.Username);
           @groups 
        }
    }
    

    Thank you for your help! :-)

    /Daniel

  • Dan Lister 416 posts 1973 karma points c-trib
    Dec 04, 2014 @ 12:43
    Dan Lister
    100

    Hi Daniel,

    You'll need an extra for each loop to iterate through each member's groups. This should do the trick:

    @{
        int total;
        var members = ApplicationContext.Services.MemberService.GetAll(1, 0, out total);
    
        foreach (var member in members)
        {
            var groups = Roles.GetRolesForUser(member.Username);
    
            if (!groups.Any())
            {
                continue;
            }
    
            foreach (var group in groups)
            {
                @group
            }
        }
    }
    

    Hope that helps.

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Dec 04, 2014 @ 13:01
    Daniel Larsen
    0

    Thank you very much for helping me!

    I get this error unfortunatly: "The name 'ApplicationContext' does not exist in the current context"

    /Daniel

  • Dan Lister 416 posts 1973 karma points c-trib
    Dec 04, 2014 @ 13:31
    Dan Lister
    1

    Hmmm strange. Maybe try using the following instead. Although I'd suggest only using the new Services if possible.

    var members = umbraco.cms.businesslogic.member.Member.GetAllAsList()
    

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Dec 04, 2014 @ 13:44
    Daniel Larsen
    0

    Thank you!

    Can it have anything to do with me using macroscripts and not partial views?

    That did not work either.

    /Daniel

  • 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