Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 12:00
    Tony Groome
    0

    How to Display a list of Members

    Hi All

    I am trying to display a list of members in my front end. So I have created a doc type and template with a heading and a content section (RTE). My members are a part of some groups like IT, Accounts and Sales. I want to display their details: first name, surname, email and phone number in a list. As there are only about 120 employees here it shouldn't be too big!

    Any ideas?

    I tried:

    @foreach(var name in ApplicationContext.Current.Services.MemberService) { @name
    }

    just to try to show the name and then build up to the email and phone number after.

    Am I way off?

    Thanks.

    Tony

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 08, 2015 @ 12:32
    Alex Skrypnyk
    101

    Hi Tony,

    Did you try like that :

    @foreach (var member in ApplicationContext.Current.Services.MemberService.GetAllMembers())
            {
                @member.Name
            }
    
  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 13:15
    Tony Groome
    0

    Hi Alex

    Excellent that spits them out from members! Is it possible to find the members which are of a custom type? I created a few custom types IT member, Accounts member and in there I have a custom tab called Details and here I have properties called First Name, Surname, Email and Phone. Is it possible to pull this data? And alphabetise it?

    Thanks. :)

    Tony

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 08, 2015 @ 13:20
    Dennis Aaen
    1

    Hi Tony.

    I think that you should have a look at the MemberService documentation. You can find the different methods here: https://our.umbraco.org/DOCUMENTATION/Reference/Management-v6/Services/MemberService

    Hope this helps,

    /Dennis

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 08, 2015 @ 13:22
    Alex Skrypnyk
    1

    There few methods in the MemberService:

    • GetMembersByGroup()
    • GetMembersByMemberType()
    • GetMembersByPropertyValue()

    You can use one of them, and ugly but:

    • GetAllMembers().Where(member => member.ContentTypeAlias.Equals("YouMemberTypeAlias"))

    Thanks, Alex

  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 13:47
    Tony Groome
    0

    Hi Guys

    Thanks for the suggestions

    I've tried a few methods like

    @foreach (var member in ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("IT Member")) { @member.Email

        }
    

    At least it compiles, though it returns nothing. I think the foreach is finding the member type and Email is not a type so it returns nothing? Am I along the right path? So to find Email we need to get to the layer below member type as Email is a property of the Details tab on the ITMember type. Phew! Does that make sense?

    Thanks.

    Tony

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 08, 2015 @ 13:52
    Alex Skrypnyk
    1

    Tony, maybe it's wrong membertype name ? or alias ?

  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 15:09
    Tony Groome
    0

    Alex

    It was the wrong member type, but it's only finding the standard Child items: Name, Email, Username (Last edited won't work - probably because it's two words!). I'm looking for the custom fields as one of them in phone number....

    Thanks. Tony

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 08, 2015 @ 15:12
    Alex Skrypnyk
    1

    Tony, custom fields are retrieving by method GetValue()

    var phone = member.GetValue("phone");
    

    Thanks, Alex

  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 15:18
    Tony Groome
    0

    Hi Alex

    That's deadly! I forgot one last thing, is there a way to .OrderBy and order them alphabetically according to name? I couldn't find a method in Dennis' list of methods?

    Thanks.

    Tony

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 08, 2015 @ 16:17
    Alex Skrypnyk
    1

    Something like that :

    ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("IT Member").OrderBy(member => member.Name);
    
  • Tony Groome 261 posts 804 karma points
    May 08, 2015 @ 16:26
    Tony Groome
    1

    Excellent stuff! Sorted! Thanks a lot.

    Tony

Please Sign in or register to post replies

Write your reply to:

Draft