Beispiel #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();
            }
        }
Beispiel #2
0
        public override void CreateUserRole(User user, Role role)
        {
            using (var transaction = new TransactionScope(mConfiguration))
            {
                var usersInRolesStore = new UserInRoleDataStore(transaction);
                var userInRole        = new UserInRole(ApplicationName, user, role);
                usersInRolesStore.Insert(userInRole);

                transaction.Commit();
            }
        }