/// <summary>
        ///     Initializes a new instance of the <see cref="AddRelationshipDialog" /> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="selectedEntityId">The selected entity identifier.</param>
        /// <param name="forward">if set to <c>true</c> [forward].</param>
        public AddRelationshipDialog(IPluginSettings settings, long selectedEntityId, bool forward)
        {
            InitializeComponent( );

            _viewModel = new AddRelationshipDialogViewModel(settings, selectedEntityId, forward);

            DataContext = _viewModel;
        }
        /// <summary>
        ///     Adds the relationship.
        /// </summary>
        /// <param name="isForward">if set to <c>true</c> [is forward].</param>
        private void AddRelationship(bool isForward)
        {
            long id;

            if (IsEntityValid(SelectedText, out id))
            {
                AddRelationshipDialog dialog = new AddRelationshipDialog(PluginSettings, id, isForward);
                var result = dialog.ShowDialog( );

                if (result == true)
                {
                    AddRelationshipDialogViewModel vm = dialog.DataContext as AddRelationshipDialogViewModel;

                    if (vm != null)
                    {
                        RelationshipPicker selectedRelationship = vm.SelectedRelationship;

                        if (selectedRelationship != null && selectedRelationship.SelectedInstance != null)
                        {
                            var instance = selectedRelationship.SelectedInstance;

                            var dbManager = new DatabaseManager(PluginSettings.DatabaseSettings);

                            string commandText = @"--ReadiMon: Insert Relationship
DECLARE @contextInfo VARBINARY(128) = CONVERT( VARBINARY(128), 'Entity Browser->Add Relationship' )
SET CONTEXT_INFO @contextInfo

INSERT INTO Relationship (TenantId, TypeId, FromId, ToId) VALUES (@tenantId, @typeId, @fromId, @toId)";


                            using (var command = dbManager.CreateCommand(commandText))
                            {
                                dbManager.AddParameter(command, "@tenantId", selectedRelationship.TenantId);
                                dbManager.AddParameter(command, "@typeId", selectedRelationship.Id);
                                dbManager.AddParameter(command, "@fromId", selectedRelationship.IsForward ? SelectedEntityId : instance.Id);
                                dbManager.AddParameter(command, "@toId", selectedRelationship.IsForward ? instance.Id : SelectedEntityId);

                                command.ExecuteNonQuery( );

                                LoadEntity(SelectedText, true);
                            }
                        }
                    }
                }
            }
        }