Пример #1
0
        public static List <string> FilterByReadPermission(List <string> ids, long idTrustee)
        {
            ISession session = null;
            var      res     = new List <string>();

            try
            {
                session = GISAUtils.SessionFactory.OpenSession();

                using (SqlCommand command = new SqlCommand(string.Empty, (SqlConnection)session.Connection))
                {
                    GISAUtils.ImportIDs(ids.ToArray(), (SqlConnection)session.Connection);
                    command.CommandText = "CREATE TABLE #effective (IDNivel BIGINT PRIMARY KEY, IDUpper BIGINT, Ler TINYINT)";
                    command.ExecuteNonQuery();

                    command.CommandText = "INSERT INTO #effective SELECT ID, ID, null FROM #temp ORDER BY #temp.seq_nr";
                    command.ExecuteNonQuery();

                    command.CommandText = "sp_getEffectiveReadPermissions";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@IDTrustee", SqlDbType.BigInt);
                    command.Parameters[0].Value = idTrustee;
                    command.ExecuteNonQuery();
                    command.Parameters.Clear();

                    command.CommandType = CommandType.Text;
                    command.CommandText = "SELECT IDNivel FROM #effective INNER JOIN #temp ON #temp.ID = #effective.IDNivel WHERE Ler = 1 ORDER BY #temp.seq_nr";
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        res.Add(reader.GetInt64(0).ToString());
                    }
                    reader.Close();
                }
            }
            catch (Exception) { throw; }
            finally
            {
                if (session != null)
                {
                    session.Close();
                }
            }
            return(res);
        }