I'm creating some different lists of Members from the Member section, and want to limit/populate the lists with Members based on their MemberType. My problem is that I don't see this property anyway (only when creating a new member).
Does anybody know if the MemberType is part of the properties I can get from calling:
"member.getProperty("MemberType").Value" or something similar.
The three types of members I'm creating lists for are in the same MemberGroup, so "if (member.Groups.ContainsKey(memberId))" is not an option. But I want to do something similar with MemberType if this is possible.
For reference my code (and check in if-statement) ended up looking like this (List of members narrowed by MemberGroup and MemberType):
List<Member> list = new List<Member>(); Member[] getAll = Member.GetAll; int memberId = umbraco.cms.businesslogic.member.MemberGroup.GetByName(MemberGroup).Id; foreach (Member member in getAll) { if (member.Groups.ContainsKey(memberId) && member.ContentType.Alias.Equals("MemberTypeAlias")) { list.Add(member); } } list.Sort((a, b) => a.LoginName.CompareTo(b.LoginName)); return models;
Getting MemberType from Member
Hi All,
I'm creating some different lists of Members from the Member section, and want to limit/populate the lists with Members based on their MemberType. My problem is that I don't see this property anyway (only when creating a new member).
Does anybody know if the MemberType is part of the properties I can get from calling:
"member.getProperty("MemberType").Value" or something similar.
The three types of members I'm creating lists for are in the same MemberGroup, so "if (member.Groups.ContainsKey(memberId))" is not an option. But I want to do something similar with MemberType if this is possible.
Umbraco version 4.0.2.1
ASP.NET 3.5
Thanks,
- Morten
Hi Morten,
I think you could use member.ContentType
Cheers,
Richard
Works like a charm!
Thanks Richard.
For reference my code (and check in if-statement) ended up looking like this (List of members narrowed by MemberGroup and MemberType):
List<Member> list = new List<Member>();
Member[] getAll = Member.GetAll;
int memberId = umbraco.cms.businesslogic.member.MemberGroup.GetByName(MemberGroup).Id;
foreach (Member member in getAll)
{
if (member.Groups.ContainsKey(memberId) && member.ContentType.Alias.Equals("MemberTypeAlias"))
{
list.Add(member);
}
}
list.Sort((a, b) => a.LoginName.CompareTo(b.LoginName));
return models;
Hi Morten,
For more performance you may try this, so that it doesnt loop through all the members.
foreach (umbraco.cms.businesslogic.Content content in Member.getContentOfContentType(MemberType.GetByAlias(" MemberTypeAlias ")))
{
Member member = new Member(content.Id);
//eg
string name= member.getProperty("MemberType").Value;
}
var m = Member.GetCurrentMember();
string mtAlias = m.ContentType.Alias;
var mt = MemberType.GetByAlias(mtAlias);
Post is a bit outdated but when you search Google for this subject you end up here. So here is the latest method:
List
is working on a reply...