Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through Membership List?

I have a list of all memberships:

Dim allUsers = Membership.GetAllUsers().Cast(Of MembershipUser).ToList

Despite my searches, I have been unable to figure out how to loop through this to do something like the following. I want to loop through and retrieve a record, if the record contains a certain value, add the user to a new collection.

for each allusers as user

  ' get user profile
  ' if user profile has a certain value, add it to another collection

end for each

Then, once the new collection is full, output that collection to my view.

Does that make sense? How can I do this? Thank you.

like image 663
user1477388 Avatar asked Feb 19 '23 13:02

user1477388


1 Answers

Try this:

Public Function GetUsers() As IEnumerable(Of MembershipUser)

    Dim newListOfUsers = New List(Of MembershipUser)()
    Dim users As MembershipUserCollection = Membership.GetAllUsers()
    For Each user As MembershipUser In users
        If user.Comment = "A Leather Glove" Then
            newListOfUsers.Add(user)
        End If
    Next

    Return newListOfUsers
End Function
like image 176
CD Smith Avatar answered Feb 23 '23 10:02

CD Smith