Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        /* 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();
        }
Ejemplo n.º 4
0
        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();
        }