Using current membership you can extend Role entity with your own fields that you need for your business logic. All this field would be saved to the same collection. To do this you need:
  1. Create class that would represent extended role in your system and add any fields you want. This class must be inherited from MembershipRoleBase.
    public class SampleRole : MembershipRoleBase
    {
        public Guid OrgId { get; set; }
    }
  1. To do CRUD operations and more you need to create RoleService. For this use code snippet:
     public interface IRolesService : IBaseService<SampleRole >
     {
         SampleRole CreateRole(string name);
     }

    public class DefaultRolesService : BaseRolesService<SampleRole>, IRolesService 
    {
        public DefaultRolesService(string connString)
            : base(connString)
        {

        }

        public SampleRole CreateRole(string name)
        {
            MembershipRole role = new MembershipRole { RoleName = name };

            GetDefaultCollection().Save(role);

            return role;
        }
    }

  1. When you are done with all this you can use it. Here is sample of usage:
    // ConnectonString sample format mongodb://127.0.0.1/{database_name}
    IRolesService service = new DefaultRolesService("ConnectionString"); 
    service.CreateRole("RoleName");
    service.Save(profile);


That's it. Have a fun :)

Last edited Aug 3, 2013 at 7:15 AM by F0rc0sigan, version 1

Comments

No comments yet.