private void EditDataServerCommand(object parameter) { if (!(parameter is TreeNodeViewModel treeNode)) { return; } if (!(treeNode.NodePayload is DatabaseServer server)) { return; } // make copy of server settings to rollback changes if needed DatabaseServer serverCopy = server.Copy(); // edit server settings ConnectSQLServerDialogWindow dialog = new ConnectSQLServerDialogWindow(serverCopy); _ = dialog.ShowDialog(); if (dialog.Result == null) { return; } string serverCopyName = string.IsNullOrWhiteSpace(serverCopy.Address) ? serverCopy.Name : $"{serverCopy.Name} ({serverCopy.Address})"; // check if new server name already exists if (serverCopy.Name != server.Name) { if (DatabaseServerNameExists(serverCopy)) { MessageBox.Show("SQL сервер " + serverCopyName + " уже сущестует.", "DaJet", MessageBoxButton.OK, MessageBoxImage.Information); return; } } // check if new server address already exists if (serverCopy.Address != server.Address) { if (DatabaseServerAddressExists(serverCopy)) { MessageBox.Show("SQL сервер " + serverCopyName + " уже сущестует.", "DaJet", MessageBoxButton.OK, MessageBoxImage.Information); return; } } // persist server settings changes serverCopy.CopyTo(server); SaveMetadataSettings(); // show server name and address changes in UI treeNode.NodeText = serverCopyName; }
[HttpPut("server/{uuid}")] public async Task <ActionResult> UpdateDatabaseServer([FromRoute] Guid uuid, [FromBody] DatabaseServer server) { if (server.Identity != uuid) { return(BadRequest()); } DatabaseServer existing = Metadata.Servers.Where(s => s.Identity == uuid).FirstOrDefault(); if (existing == null) { return(NotFound()); } server.CopyTo(existing); SaveMetadataSettings(); return(Ok()); }