Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Jan 19, 2011 @ 15:40
    Lee
    1

    Create Member Groups/Types & Properties Programatically

    I have the need to create a specific Member Group/Type programatically and then add specific properties to it, this is for a package I'm creating and will be done via a usercontrol.

    Anyone know of a package that does this?  So I can check out how they went about it, or if you have done it a snippet example of code would be really helpful :)

  • Lee 1130 posts 3088 karma points
    Jan 19, 2011 @ 20:36
    Lee
    0

    anyone :S  Guess I'll be digging in Umbraco source

  • Lee 1130 posts 3088 karma points
    Jan 26, 2011 @ 15:57
    Lee
    0

    Bump :S

  • Lee 1130 posts 3088 karma points
    Jan 26, 2011 @ 19:52
    Lee
    1

    For anyone interested, heres how I did - This basically creates a membertype and group with an alias of 'ForumUser', adds a tab called 'Content' to the member type and adds three properties to the Member type (1 x Textstring, 2 x Numeric)

                const string memberTypeAlias = "ForumUser";
                const string memberTypeName = "Forum User";
                const string memberTabName = "Content";
                const int textStringId = -88;
                const int numericId = -51;
                const string forumUserTwitterUrl = "forumUserTwitterUrl";
                const string forumUserPosts = "forumUserPosts";
                const string forumUserKarma = "forumUserKarma";
    
                // First Create the MemberType
                var mt = CreateMemberType(memberTypeAlias, memberTypeName);
    
                // Now create the tab
                mt.AddVirtualTab(memberTabName);
    
                // Add the properties            
                // 1) forumUserTwitterUrl > textString
                var dt = DataTypeDefinition.GetDataTypeDefinition(textStringId);
                mt.AddPropertyType(dt, forumUserTwitterUrl, "Twitter Username");
                var prop = mt.getPropertyType(forumUserTwitterUrl);
                prop.Mandatory = false;
                prop.TabId = GetTabByCaption(mt, memberTabName).Id;
                prop.Save();
    
                // 2) forumUserPosts > Numeric
                dt = DataTypeDefinition.GetDataTypeDefinition(numericId);
                mt.AddPropertyType(dt, forumUserPosts, "Users Post Amount");
                prop = mt.getPropertyType(forumUserPosts);
                prop.Mandatory = false;
                prop.TabId = GetTabByCaption(mt, memberTabName).Id;
                prop.Save();
    
                // 3) forumUserKarma > Numeric
                dt = DataTypeDefinition.GetDataTypeDefinition(numericId);
                mt.AddPropertyType(dt, forumUserKarma, "Users Karma Amount");
                prop = mt.getPropertyType(forumUserKarma);
                prop.Mandatory = false;
                prop.TabId = GetTabByCaption(mt, memberTabName).Id;
                prop.Save();
    
                // Lastly create the group
                MemberGroup.MakeNew(memberTypeAlias, User.GetUser(0));

    Hope it helps someone :)

  • CASTELLI 23 posts 76 karma points
    Jun 18, 2013 @ 16:42
    CASTELLI
    1

    Hi,

    This is just what I was looking for.


    Unfortunatly, I got stuck on the first line of code : CreateMemberType is not recognised ! I'm using Umbraco v6.
    I found out I could replace that line with :

      MemberType mt = MemberType.MakeNew(User.GetUser(0), memberTypeAlias);

    I then got stuck on another unrecognised method GetTabByCaption :
    But it could be replaced with :

      prop.TabId= iTabID;

    Where iTabID is instantiated when creating the new tab like so:

      // Now create the tab
      int iTabID = mt
    .AddVirtualTab(memberTabName);

    Thanks Lee, it did help some1
    Hope it helps some others 2 ...

  • Martin Lingstuyl 202 posts 379 karma points
    Jul 04, 2014 @ 21:20
    Martin Lingstuyl
    1

    Guys,

    I had trouble too. (umbraco 6.2.1) But I finally got it like this:

    Creating the membertype

    public static MemberType CreateSimpleMemberType(string alias = null, string name = null)
            {
               
                var memberType = new MemberType(-1)
                {
                    Alias = alias ?? "simple",
                    Name = name ?? "Simple member",
                    Description = "Some member type",
                    Icon = ".sprTreeDoc3",
                    Thumbnail = "user.png",
                    SortOrder = 1,
                    CreatorId = 0,
                    Trashed = false
                };

                return memberType;
               
            }

     

    Creating Properties in tabs + saving it

    memberType.AddPropertyGroup("customtab");

    var TextBoxDefinition = new DataTypeDefinition(-1, new Guid(Constants.PropertyEditors.Textbox));

    memberType.AddPropertyType(new PropertyType(TextBoxDefinition) { Alias = "alias", Name = "Name", Description = "", Mandatory = false, SortOrder = 1 }, "customtab");

    mts.Save(memberType);

     

    The following functions couldnt be found (dont know whats going on here)

    dt =DataTypeDefinition.GetDataTypeDefinition(numericId);
    var mt =CreateMemberType(memberTypeAlias, memberTypeName);
    mt.AddVirtualTab(memberTabName);
  • Charles Afford 1163 posts 1709 karma points
    Jul 05, 2014 @ 10:44
    Charles Afford
    0

    Hi take a look at http://www.charlesafford.com/blog-folder/umbraco-members-and-aspnet-membership-provider-1-1/

    This should point you in the right direction :)

  • J 447 posts 864 karma points
    Jul 17, 2019 @ 14:42
    J
    0

    Anyone know the equivalent of the MemberType in Umbraco 7? Currently using Umbraco.Core.Models, but receive an error getting to the method MakeNew

    MemberType.MakeNew
    
Please Sign in or register to post replies

Write your reply to:

Draft