/// <summary>
        /// Updates the integration service call settings.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentNullException">dto</exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        public void UpdateIntegrationServiceCallSettings(IntegrationServiceCallSettingsDto dto)
        {
            const string CommandText = @"
UPDATE [dbo].[IntegrationServiceCallSettings]
SET
     [ServiceId] = @serviceId
    ,[LastModifiedOn] = GETDATE()
    ,[CallType] = @callType
WHERE [Id] = @id;";

            if (dto == null)
                throw new ArgumentNullException("dto");

            using (var cmd = new SqlCommand(CommandText))
            {
                cmd.Parameters.AddWithValue("@id", dto.Id);
                cmd.Parameters.AddWithValue("@serviceId", dto.ServiceId);
                cmd.Parameters.AddWithValue("@callType", dto.CallType.ToString());

                var rowsAffected = Database.Execute(cmd);

                if (rowsAffected == 0)
                    throw new DBConcurrencyException(ConcurencyException);
            }
        }
        /// <summary>
        /// Reads the integration service call rules.
        /// </summary>
        /// <param name="callSettingsDto">The call settings dto.</param>
        /// <param name="reader">The reader.</param>
        private static void ReadIntegrationServiceCallRules(IntegrationServiceCallSettingsDto callSettingsDto, IDataReader reader)
        {
            reader.NextResult();

            while (reader.Read())
            {
                var ruleDto = new IntegrationServiceCallRuleDto { Id = reader.GetInt32(0), RuleGuid = reader.GetGuid(1) };
                callSettingsDto.Rules.Add(ruleDto);
            }
        }
        /// <summary>
        /// Inserts the integration service call settings.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentNullException">dto</exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        public void InsertIntegrationServiceCallSettings(IntegrationServiceCallSettingsDto dto)
        {
            const string CommandText = @"
INSERT INTO [dbo].[IntegrationServiceCallSettings]
(
     [ServiceId]
    ,[LastModifiedOn]
    ,[CallType]
)
VALUES
(
     @serviceId
    ,GETDATE()
    ,@callType
);

SET @id = SCOPE_IDENTITY();";

            if (dto == null)
                throw new ArgumentNullException("dto");

            using (var cmd = new SqlCommand(CommandText))
            {
                var idParam = cmd.Parameters.Add("@id", SqlDbType.Int);

                idParam.Direction = ParameterDirection.Output;

                cmd.Parameters.AddWithValue("@serviceId", dto.ServiceId);
                cmd.Parameters.AddWithValue("@callType", dto.CallType.ToString());

                var rowsAffected = Database.Execute(cmd);

                if (rowsAffected == 0)
                    throw new DBConcurrencyException(ConcurencyException);

                dto.Id = (int)idParam.Value;
            }
        }
        /// <summary>
        /// Fetches the integration service call settings.
        /// </summary>
        /// <param name="serviceId">The service identifier.</param>
        /// <returns>IntegrationServiceCallSettingsDto.</returns>
        public IntegrationServiceCallSettingsDto FetchIntegrationServiceCallSettings(int serviceId)
        {
            const string CommandText = @"
DECLARE @settingsId INT

SELECT @settingsId = [Id]
FROM
    [dbo].[IntegrationServiceCallSettings]
WHERE [ServiceId] = @serviceId;

SELECT
     [Id]
    ,[CallType]
FROM
    [dbo].[IntegrationServiceCallSettings]
WHERE [Id] = @settingsId;

SELECT
     [Id]
    ,[RuleGuid]
FROM
    [dbo].[IntegrationServiceCallRules]
WHERE [CallSettingsId] = @settingsId;";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                using (var cmd = new SqlCommand(CommandText, ctx.Connection))
                {
                    cmd.Parameters.AddWithValue("@serviceId", serviceId);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            var result = new IntegrationServiceCallSettingsDto
                                             {
                                                 Id = reader.GetInt32(0),
                                                 CallType =
                                                     (ServiceCallType)
                                                     Enum.Parse(typeof(ServiceCallType), reader.GetString(1), true)
                                             };

                            ReadIntegrationServiceCallRules(result, reader);

                            return result;
                        }
                    }
                }
            }

            return null;
        }