public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            if (usernames != null && usernames.Length > 0 && roleNames != null && roleNames.Length > 0)
            {
                using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
                {
                    CustomRole role = null;
                    IList<CustomUser> usersToBeRemoved = null;
                    CustomRoleDAO roleDAO = new CustomRoleDAO();
                    // remove users for each role
                    foreach (String roleName in roleNames)
                    {
                        role = roleDAO.FindByName(roleName, ApplicationName);
                        if (role != null)
                        {
                            if (role.Users != null && role.Users.Count > 0)
                            {
                                // get all matched users (users to be removed) from the current role
                                var query = (from u in role.Users
                                             where usernames.Any(name => name == u.Name)
                                                 select u
                                            );
                                if (query != null && query.Count() > 0)
                                {
                                    usersToBeRemoved = query.ToList();

                                    // remove each matched user from the role
                                    foreach (CustomUser userToBeRemoved in usersToBeRemoved)
                                    {
                                        role.Users.Remove(userToBeRemoved);
                                    }
                                }
                                // persist role
                                roleDAO.SaveOrUpdate(role);
                            }
                        }
                    }

                    transaction.Complete();
                }
            }
        }
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     if (usernames != null && usernames.Length > 0 && roleNames != null && roleNames.Length > 0)
     {
         using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
         {
             CustomUser user = null;
             CustomRole role = null;
             foreach (String roleName in roleNames)
             {
                 CustomUserDAO userDAO = new CustomUserDAO();
                 CustomRoleDAO roleDAO = new CustomRoleDAO();
                 role = roleDAO.FindByName(roleName, ApplicationName);
                 if (role != null)
                 {
                     foreach (String userName in usernames)
                     {
                         user = userDAO.FindByName(userName, ApplicationName);
                         if (role.Users == null)
                         {
                             role.Users = new HashSet<CustomUser>();
                         }
                         if (!role.Users.Contains(user))
                         {
                             role.Users.Add(user);
                         }
                     }
                     roleDAO.SaveOrUpdate(role);
                 }
             }
             transaction.Complete();
         }
     }
 }
        public override void CreateRole(string roleName)
        {
            if (roleName == null || roleName.Trim().Length == 0)
            {
                throw new ArgumentException("The rolename cannot be null nor empty");
            }

            CustomRoleDAO roleDAO = new CustomRoleDAO();
            roleDAO.SaveOrUpdate(new CustomRole(roleName, membershipApplication));
        }