/// <summary>
 /// Creates an authorization attribute.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public IAzManAttribute <IAzManAuthorization> CreateAttribute(string key, string value)
 {
     try
     {
         //db.tAuthorizationattributes.Insert(this.authorizationId, key, value);
         int authorizationAttributeId = 0;
         authorizationAttributeId = this.db.AuthorizationAttributeInsert(this.authorizationId, key, value, this.item.Application.ApplicationId);
         this.db.SubmitChanges();
         IAzManAttribute <IAzManAuthorization> result = new SqlAzManAuthorizationAttribute(this.db, this, authorizationAttributeId, key, value, this.ens);
         this.raiseAuthorizationAttributeCreated(this, result);
         if (this.ens != null)
         {
             this.ens.AddPublisher(result);
         }
         return(result);
     }
     catch (System.Data.SqlClient.SqlException sqlex)
     {
         if (sqlex.Number == 2601) //Index Duplicate Error
         {
             throw SqlAzManException.AttributeDuplicateException(key, this, sqlex);
         }
         else
         {
             throw SqlAzManException.GenericException(sqlex);
         }
     }
 }
        /// <summary>
        /// Gets the authorization attribute.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public IAzManAttribute <IAzManAuthorization> GetAttribute(string key)
        {
            AuthorizationAttributesResult attr;

            if ((attr = (from t in this.db.AuthorizationAttributes() where t.AuthorizationId == this.authorizationId && t.AttributeKey == key select t).FirstOrDefault()) != null)
            {
                IAzManAttribute <IAzManAuthorization> result = new SqlAzManAuthorizationAttribute(this.db, this, attr.AuthorizationAttributeId.Value, attr.AttributeKey, attr.AttributeValue, this.ens);
                if (this.ens != null)
                {
                    this.ens.AddPublisher(result);
                }
                return(result);
            }
            else
            {
                throw SqlAzManException.AttributeNotFoundException(key, this, null);
            }
        }
        /// <summary>
        /// Gets the authorization attributes.
        /// </summary>
        /// <returns></returns>
        public IAzManAttribute <IAzManAuthorization>[] GetAttributes()
        {
            IAzManAttribute <IAzManAuthorization>[] attributes;
            var attrs = (from a in this.db.AuthorizationAttributes()
                         where a.AuthorizationId == this.authorizationId
                         select a).ToList();

            attributes = new SqlAzManAttribute <IAzManAuthorization> [attrs.Count];
            int index = 0;

            foreach (var row in attrs)
            {
                attributes[index] = new SqlAzManAuthorizationAttribute(this.db, this, row.AuthorizationAttributeId.Value, row.AttributeKey, row.AttributeValue, this.ens);
                if (this.ens != null)
                {
                    this.ens.AddPublisher(attributes[index]);
                }
                index++;
            }
            return(attributes);
        }