Exemplo n.º 1
0
        private void UpdateUsersRolesList(IStorageSession session, UserEntity userEntity, IEnumerable <string> newRoles)
        {
            var newRolesList = newRoles.Any()
                                   ? session.Query <RoleEntity>(staleResults: StaleResultsMode.WaitForNonStaleResults)
                               .ContainsIn(r => r.RoleName, newRoles)
                               .ToList()
                                   : Enumerable.Empty <RoleEntity>();

            var roleNamesToRemove = userEntity.GetRolesToRemove(newRoles);

            foreach (var roleName in roleNamesToRemove)
            {
                if (userEntity.RemoveRole(roleName))
                {
                    _log.Debug(m => m("remove role by name {0}", roleName));
                }
            }

            foreach (var roleEntity in newRolesList)
            {
                if (userEntity.AddRole(roleEntity.RoleName))
                {
                    _log.Debug(m => m("Added user {0} to role {1}", userEntity, roleEntity));
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateUsersRolesList(IStorageSession session, UserEntity userEntity, IEnumerable<string> newRoles)
        {
            var newRolesList = newRoles.Any()
                                   ? session.Query<RoleEntity>(staleResults: StaleResultsMode.WaitForNonStaleResults)
                                         .ContainsIn(r => r.RoleName, newRoles)
                                         .ToList()
                                   : Enumerable.Empty<RoleEntity>();

            var roleNamesToRemove = userEntity.GetRolesToRemove(newRoles);
            foreach (var roleName in roleNamesToRemove)
            {
                if (userEntity.RemoveRole(roleName))
                {
                    _log.Debug(m => m("remove role by name {0}", roleName));
                }
            }

            foreach (var roleEntity in newRolesList)
            {
                if (userEntity.AddRole(roleEntity.RoleName))
                {
                    _log.Debug(m => m("Added user {0} to role {1}", userEntity, roleEntity));
                }
            }
        }