コード例 #1
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            using (var transaction = new TransactionScope(mConfiguration))
            {
                var usersInRolesStore = new UserInRoleDataStore(transaction);

                foreach (string userName in usernames)
                {
                    foreach (string roleName in roleNames)
                    {
                        var        rDS        = new RoleDataStore(transaction);
                        Role       role       = rDS.FindByName(mApplicationName, roleName);
                        var        uDS        = new UserDataStore(transaction);
                        User       user       = uDS.FindByName(mApplicationName, userName);
                        UserInRole userInRole = usersInRolesStore.Find(ApplicationName, user, role);
                        if (userInRole == null)
                        {
                            throw new UserInRoleNotFoundException(userName, roleName);
                        }

                        userInRole.Deleted = true;
                        usersInRolesStore.Update(userInRole);
                    }
                }

                transaction.Commit();
            }
        }
コード例 #2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            using (var transaction = new TransactionScope(mConfiguration))
            {
                var  rDS  = new RoleDataStore(transaction);
                Role role = rDS.FindByName(mApplicationName, roleName);
                var  uDS  = new UserDataStore(transaction);
                User user = uDS.FindByName(mApplicationName, username);
                var  userInRoleDataStore = new UserInRoleDataStore(transaction);

                if (userInRoleDataStore.Find(ApplicationName, user, role) != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }