Copied to clipboard

Flag this post as spam?

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


  • Max Edwards 26 posts 50 karma points
    Jul 08, 2010 @ 13:09
    Max Edwards
    0

    Get members by member group

    I'm trying to list the members by the member group but I can't see a method to get a member by either group or type. The code below is working but it does a recursive loop over every member for every group in the installation which is not good.

    Does anyone know of a better way to do this?

            MemberGroup[] memberGroups = MemberGroup.GetAll;
    
            foreach(var memberGroup in memberGroups)
            {
                Response.Write("<b>" + memberGroup.Text + "</b><br />");
                Member[] members = Member.GetAll;
                foreach (var member in members)
                {
                    if(member.Groups.ContainsKey(memberGroup.Id))
                    {
                        Response.Write(member.LoginName + "<br />");
                    }
                }
            }

    Ignore the response write, this is just for debugging.

    Max

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 08, 2010 @ 13:36
    Matt Brailsford
    2

    You could use the roles provider?

    Roles.GetUsersInRole("memberGroup");

    This would get you a list of user names, so if you just pulled all members back and cross referenced, that could work?

    Matt

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 08, 2010 @ 13:37
    Dirk De Grave
    0

    Have a look at this post, especially reply from @slace...

     

    Hope this helps.

    Regards,

    /Dirk

     

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jul 08, 2010 @ 13:39
    Tim
    0

    Hiya,

    The member group class has a getmembers method, that should be what you're after:

    http://umbraco.org/apiDocs/html/AllMembers_T_umbraco_cms_businesslogic_member_MemberGroup.htm

  • Max Edwards 26 posts 50 karma points
    Jul 08, 2010 @ 13:57
    Max Edwards
    0

    Perfect, thanks for all the answers.

    I will use roles provider as this seems like the preferred method.

  • MK 429 posts 906 karma points
    Mar 21, 2012 @ 11:26
    MK
    0

    Hi there,

    Im trying to get all the member of a specific group and I was able to get their names using the Roles.GetUsersInRole("memberGroup");

    However, it seems like all I get is their names. How can I get all the other properties like address and id?

    Many thanks

    mkariti

     

  • MK 429 posts 906 karma points
    Mar 22, 2012 @ 12:42
    MK
    0

    Anyone know how to achieve this?

    Im using this one:

     

    MemberGroup.GetByName("Supplier").GetMembers();
    

    But is says that this is an  obsolete  method --> please use the .Role.getuser

    What does it means by 
    obsolete ? 

    Also, can anyone post an example? as I said above I only get the name without anyother details like Id.

    Cheers

    mkariti

     

  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 13:05
    Grant Thomas
    0

    mkariti,

    I've never messed with Members in Umbraco but 'obsolete' in general means that, although such functionality is still available, it is only for backwards compatibility purposes, should be considered deprecated and should not be used; this is almost always because a newer, more desirable way of doing the thing has been introduced (big but here though: it should still do what is always did and that should not change!).

    So, I'm doing this a lot here these days, but to guess, you might consider doing what it says and using 'Role.GetUser'; however since you use a couple of methods there I'm not 100% sure which of those is actually deprecated, so let's just replace it and see what happens (incidentally, with the code above posted by Matt):

    Roles.GetUsersInRole("Supplier")
  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 13:07
    Grant Thomas
    0

    Anotner note, community-wise, is that since this problem has been marked as 'solved' and you didn't manage to derive a fix for yourself from the proposed solution, starting a topic dedicated to your problem seems more proper.

  • MK 429 posts 906 karma points
    Mar 22, 2012 @ 13:34
    MK
    0

    Hi Grant,

    Many thanks for your reply.

    So basically the best bet will be to use 2 methods? 1 to get the names and the second to reference to other method let say to get the ID's?

    Also, duly noted regarding the solved Message.

    Many thanks

    mkariti

     

     


  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 13:39
    Grant Thomas
    0

    Might this work?

    foreach (var userInRole in Roles.GetUsersInRole("Supplier")) {
      var user = new MembershipUser(userInRole);

    Or,

    var user = Membership.GetUser(userInRole);
  • MK 429 posts 906 karma points
    Mar 22, 2012 @ 15:32
    MK
    0

    Great! 

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft