private void RemoveCategory() { // Remove from database if (SelectedCategory == null) { MessageBox.Show("Please select a category.", "No category selected", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (SelectedCategory.Children.Any()) { MessageBox.Show("Please remove child categories first.", "Remove child category", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (SelectedCategory.GetAchievements().Any()) { MessageBox.Show("Please remove achievements first.", "Remove achievements", MessageBoxButton.OK, MessageBoxImage.Warning); return; } categoryDM.Remove(SelectedCategory); // Update locations IEnumerable <Category> categories = GetCategoryParentChildrenSafe(SelectedCategory); categoryDM.DecreaseLocations(categories, SelectedCategory.Location + 1); // Refresh view and select the parent category var selectedCategory = SelectedCategory; RefreshCategoriesView(); if (selectedCategory.Parent != null) { SelectedCategory = Categories.Find(selectedCategory.Parent.ID); } }