コード例 #1
0
ファイル: PlantRepository.cs プロジェクト: Epstone/mypvlog
        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);
        }
コード例 #2
0
ファイル: PlantRepository.cs プロジェクト: Epstone/mypvlog
        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;
        }
コード例 #3
0
ファイル: PlantRepository.cs プロジェクト: Epstone/mypvlog
        /* 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();
        }
コード例 #4
0
ファイル: PlantRepository.cs プロジェクト: Epstone/mypvlog
        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();
        }