Example #1
0
        [HttpPut("{server}/database/{uuid}")] public async Task <ActionResult> UpdateDatabase([FromRoute] Guid server, [FromRoute] Guid uuid, [FromBody] DatabaseInfo database)
        {
            if (database.Identity != uuid)
            {
                return(BadRequest());
            }
            DatabaseServer srv = Metadata.Servers.Where(s => s.Identity == server).FirstOrDefault();

            if (srv == null)
            {
                return(NotFound());
            }
            DatabaseInfo existing = srv.Databases.Where(db => db.Identity == uuid).FirstOrDefault();

            if (existing == null)
            {
                return(NotFound());
            }

            IMetadataService metadata = Services.GetService <IMetadataService>();

            metadata.Initialize(srv, existing);

            database.CopyTo(existing);
            SaveMetadataSettings();

            return(Ok());
        }
Example #2
0
        private void EditDatabaseCommand(object parameter)
        {
            if (!(parameter is TreeNodeViewModel treeNode))
            {
                return;
            }
            if (!(treeNode.NodePayload is DatabaseInfo database))
            {
                return;
            }
            DatabaseServer server = treeNode.GetAncestorPayload <DatabaseServer>();

            if (server == null)
            {
                return;
            }

            // make copy of database settings to rollback changes if needed
            DatabaseInfo databaseCopy = database.Copy();

            // edit server settings
            DatabaseFormWindow dialog = new DatabaseFormWindow(databaseCopy);

            _ = dialog.ShowDialog();
            if (dialog.Result == null)
            {
                return;
            }

            string databaseCopyName    = databaseCopy.Name;
            string databaseCopyAlias   = databaseCopy.Alias;
            bool   databaseNameChanged = (databaseCopy.Name != database.Name);

            // check if new database name already exists
            if (databaseNameChanged)
            {
                if (DatabaseNameExists(server, databaseCopy))
                {
                    MessageBox.Show("База данных " + databaseCopyName + " уже сущестует.",
                                    "DaJet", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }

            // persist database settings changes
            databaseCopy.CopyTo(database);
            SaveMetadataSettings();

            if (databaseNameChanged)
            {
                for (int i = treeNode.TreeNodes.Count - 1; i > 0; i--)
                {
                    if (treeNode.TreeNodes[i].NodeText != SCRIPTS_NODE_NAME)
                    {
                        treeNode.TreeNodes.RemoveAt(i);
                    }
                }
                database.BaseObjects.Clear();

                InitializeMetadata(server, database);
                InitializeDatabaseTreeNodes(treeNode);
                treeNode.IsSelected = true;
            }
            // show new database name and alias in UI
            treeNode.NodeText    = databaseCopyName;
            treeNode.NodeToolTip = databaseCopyAlias;
        }