public bool ValidateUserUserForPlant(int userID, int systemID, E_PlantRole minimumRequiredRole) { string text = @"SELECT Count(*) FROM user_has_plant WHERE (PlantID = ?PlantID) AND (UserID = ?UserID) AND (?MinimumRole <= PlantRole);"; var sqlCom = base.GetReadCommand( text ); //add parameters sqlCom.Parameters.AddWithValue( "?PlantID", systemID ); sqlCom.Parameters.AddWithValue( "?UserID", userID ); sqlCom.Parameters.AddWithValue( "?MinimumRole", minimumRequiredRole ); return (Convert.ToInt32( sqlCom.ExecuteScalar() ) >= 1); }
public List<int> GetUsersOfSolarPlant(int systemID, E_PlantRole role) { string text = @"SELECT UserID, PlantID FROM user_has_plant WHERE (PlantID =?PlantID) AND (PlantRole = ?PlantRole);"; var sql = base.GetReadCommand( text ); sql.Parameters.AddWithValue( "?PlantID", systemID ); sql.Parameters.AddWithValue( "?PlantRole", role ); List<int> result = new List<int>(); using (var rdr = sql.ExecuteReader()) { while (rdr.Read()) { result.Add( rdr.GetInt32( "UserID" ) ); } } return result; }
/* USER PLANT AUTHORIZATION */ public void StoreUserPlantRelation(int userID, int systemID, E_PlantRole role) { string text = @"INSERT INTO user_has_plant (PlantID, UserID, PlantRole) VALUES (?PlantID, ?UserID, ?PlantRole) ON DUPLICATE KEY UPDATE PlantRole = ?PlantRole;"; var sqlCom = base.GetWriteCommand( text ); //add parameters sqlCom.Parameters.AddWithValue( "?PlantID", systemID ); sqlCom.Parameters.AddWithValue( "?UserID", userID ); sqlCom.Parameters.AddWithValue( "?PlantRole", role ); sqlCom.ExecuteNonQuery(); }
public void DeleteUserHasPlantRelation(int userID, int systemID, E_PlantRole role) { string text = @"DELETE FROM user_has_plant WHERE (PlantID = ?PlantID) AND (UserID = ?UserID) AND (PlantRole = ?PlantRole);"; var sqlCom = base.GetWriteCommand( text ); //add parameters sqlCom.Parameters.AddWithValue( "?PlantID", systemID ); sqlCom.Parameters.AddWithValue( "?UserID", userID ); sqlCom.Parameters.AddWithValue( "?PlantRole", role ); sqlCom.ExecuteNonQuery(); }