コード例 #1
0
        public override void CreateRole(string roleName)
        {
            SQLiteParameter[] isExistParms =
            {
                SU.CreateInputParam("@ApplicationId",   DbType.String, ApplicationId),
                SU.CreateInputParam("@LoweredRoleName", DbType.String, roleName.ToLower())
            };
            using (SQLiteConnection conn = SQLiteConnectionHelper.GetConnection(SqlConnectionString, true).Connection)
            {
                var obj = SQLiteHelper.ExecuteScalar(conn, CommandType.Text, Sql_Roles_IsExistName, isExistParms);
                if (obj != null)
                {
                    return;
                }

                SQLiteParameter[] parms =
                {
                    SU.CreateInputParam("@ApplicationId",   DbType.String, ApplicationId),
                    SU.CreateInputParam("@RoleId",          DbType.String, Guid.NewGuid().ToString("N")),
                    SU.CreateInputParam("@RoleName",        DbType.String, roleName),
                    SU.CreateInputParam("@LoweredRoleName", DbType.String, roleName.ToLower()),
                    SU.CreateInputParam("@Description",     DbType.String, string.Empty)
                };
                SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, Sql_Roles_Insert, parms);
            }
        }
コード例 #2
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            SQLiteParameter[] parms =
            {
                SU.CreateInputParam("@ApplicationId",   DbType.String, ApplicationId),
                SU.CreateInputParam("@LoweredRoleName", DbType.String, roleName.ToLower())
            };
            int effect = 0;

            using (SQLiteConnection conn = SQLiteConnectionHelper.GetConnection(SqlConnectionString, true).Connection)
            {
                if (throwOnPopulatedRole)
                {
                    var obj = SQLiteHelper.ExecuteScalar(conn, CommandType.Text, Sql_IsExistUserInRole, parms);
                    if (obj != null)
                    {
                        throw new ProviderException(SM.GetString(SM.Role_is_not_empty));
                    }
                }
                effect = SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, Sql_Roles_Delete, parms);
                SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, Sql_DeleteUsersByRoleName, parms);
            }

            return(effect > 0);
        }
コード例 #3
0
        private void AddUserToRole(string username, string roleName)
        {
            SQLiteParameter[] parms =
            {
                SU.CreateInputParam("@ApplicationId",   DbType.String, ApplicationId),
                SU.CreateInputParam("@LoweredUserName", DbType.String, username.ToLower()),
                SU.CreateInputParam("@LoweredRoleName", DbType.String, roleName.ToLower())
            };

            var userId = string.Empty;
            var roleId = string.Empty;
            var effect = 0;

            using (SQLiteConnection conn = SQLiteConnectionHelper.GetConnection(SqlConnectionString, true).Connection)
            {
                using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(conn, CommandType.Text, SU.Sql_Users_SelectIdByName, parms))
                {
                    if (reader.Read())
                    {
                        userId = reader.GetString(0);
                    }
                }
                using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(conn, CommandType.Text, Sql_Roles_SelectId, parms))
                {
                    if (reader.Read())
                    {
                        roleId = reader.GetString(0);
                    }
                }

                if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(roleId))
                {
                    return;
                }

                SQLiteParameter[] uirParms =
                {
                    SU.CreateInputParam("@UserId", DbType.String, userId),
                    SU.CreateInputParam("@RoleId", DbType.String, roleId)
                };

                effect = SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, SU.Sql_UsersInRoles_Insert, uirParms);
            }

            if (effect < 1)
            {
                throw new ProviderException(SM.Provider_unknown_failure);
            }
        }