/// <summary> /// 判断角色或用户是否具有系统权限 /// </summary> /// <param name="rights"> /// 系统权限对象 /// </param> public bool Exists(System_Rights rights) { if (rights == null) { throw new ArgumentNullException("rights"); } object result = null; var parameters = new List<SqlParameter> { this.SqlServer.CreateSqlParameter( "RoleID", SqlDbType.Int, rights.RoleID, ParameterDirection.Input) }; try { result = this.SqlServer.ExecuteScalar(CommandType.StoredProcedure, "sp_System_Rights_Exists", parameters, null); } catch (Exception exception) { throw new Exception("Exception - SystemRightsDA - Exists", exception); } return Convert.ToInt32(result) == 1 ? true : false; }
/// <summary> /// 新增系统权限 /// </summary> /// <param name="rights"> /// 系统权限对象 /// </param> public int Insert(System_Rights rights) { if (rights == null) { throw new ArgumentNullException("rights"); } int id; var parameters = new List<SqlParameter> { this.SqlServer.CreateSqlParameter( "UserID", SqlDbType.Int, rights.UserID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "RoleID", SqlDbType.Int, rights.RoleID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "UserRights", SqlDbType.VarChar, rights.UserRights, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "ReferenceID", SqlDbType.Int, null, ParameterDirection.Output) }; try { this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_System_Rights_Insert", parameters, null); id = (int)parameters.Find(parameter => parameter.ParameterName == "ReferenceID").Value; } catch (Exception exception) { throw new Exception("Exception - SystemRightsDA - Insert", exception); } return id; }
/// <summary> /// 修改系统权限 /// </summary> /// <param name="rights"> /// 系统权限对象 /// </param> public int Update(System_Rights rights) { if (rights == null) { throw new ArgumentNullException("rights"); } int result = 0; var parameters = new List<SqlParameter> { this.SqlServer.CreateSqlParameter( "UserID", SqlDbType.Int, rights.UserID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "RoleID", SqlDbType.Int, rights.RoleID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "UserRights", SqlDbType.VarChar, rights.UserRights, ParameterDirection.Input) }; try { result = this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_System_Rights_Update", parameters, null); } catch (Exception exception) { throw new Exception("Exception - SystemRightsDA - Update", exception); } return result; }
/// <summary> /// The modify rights. /// </summary> /// <param name="roleId"> /// The role id. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="permissions"> /// The permissions. /// </param> /// <returns> /// The <see cref="string"/> /// </returns> public int ModifyRights(int roleId, int userId, string permissions) { SystemRightsDA rightsDa = new SystemRightsDA(); System_Rights rights = new System_Rights(); rights.RoleID = roleId; rights.UserID = userId; rights.UserRights = permissions; int result = 0; if (rightsDa.Exists(rights)) { result = rightsDa.Update(rights); } else { result = rightsDa.Insert(rights); } return result; }