/// <summary>
        /// Inserts a new claim.
        /// </summary>
        /// <param name="claim"></param>
        /// <returns>
        ///     0 - Not inserted (error)
        ///     1 - Successfully inserted
        ///     2 - Gloabl claim created
        ///     3 - No action needed
        /// </returns>
        public int Insert(IdentityClaim claim)
        {
            var existingClaim = GetClaim(claim.Type, claim.Value);

            if (existingClaim != null)
            {
                // Claim already exists but not for this client: Make existing claim global
                // if it not already is!
                if (existingClaim.ClientId != null && existingClaim.ClientId != claim.ClientId)
                {
                    existingClaim.ClientId = null;
                    return(_database.Update("Claim", "Id", existingClaim) != 0 ? 2 : 0);
                }

                return(3);
            }
            else
            {
                return(_database.Insert("Claim", "", claim) != null ? 1 : 0);
            }
        }
 public int Update(IdentityClaim claim)
 {
     return
         (_database.Update("Claim", "Id", claim));
 }