示例#1
0
        /// <summary>
        /// Deletes the selected library after prompting the user.
        /// </summary>
        private void DeleteLibrary()
        {
            if (this.ActiveLibrary == null)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "No library selected");
                return;
            }

            MessageBoxResult result = CenteredDialogBox.Show(
                "Delete library '" + this.ActiveLibrary.LibraryName + "'?",
                "Confirm Library Delete",
                MessageBoxButton.YesNoCancel,
                MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                Task.Run(() =>
                {
                    try
                    {
                        AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens;
                        SqualrApi.DeleteLibrary(accessTokens?.AccessToken, this.ActiveLibrary.LibraryId);
                        this.libraries.Remove(this.ActiveLibrary);
                        this.ActiveLibrary = null;
                        this.RaisePropertyChanged(nameof(this.Libraries));
                        this.RaisePropertyChanged(nameof(this.ActiveLibrary));
                    }
                    catch (Exception ex)
                    {
                        OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error deleting library", ex);
                    }
                });
            }
        }