From 7e85159fd5a1c359007adb34845df713162a076c Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sat, 13 Apr 2024 12:07:38 +0200 Subject: [PATCH] fix removing of entries --- EliteBGS/MainWindow.xaml.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/EliteBGS/MainWindow.xaml.cs b/EliteBGS/MainWindow.xaml.cs index cec6b9e..a9b82c8 100644 --- a/EliteBGS/MainWindow.xaml.cs +++ b/EliteBGS/MainWindow.xaml.cs @@ -271,15 +271,27 @@ public partial class MainWindow : MetroWindow { object obj = entries.SelectedItem; bool removed = false; - if (obj.GetType() == typeof(Objective)) { - removed = report.Objectives.Remove(obj as Objective); + if (obj.GetType() == typeof(SystemObjectives)) { + removed = report.SystemObjectives.Remove(obj as SystemObjectives); + } else if (obj.GetType() == typeof(Objective)) { + report + .SystemObjectives + .ForEach(x => { + if (x.Objectives.Remove(obj as Objective)) { + removed = true; + } + }); } else if (obj.GetType() == typeof(UITransaction) || - obj.GetType().IsSubclassOf(typeof(UITransaction))) { - foreach (Objective parent in report.Objectives) { - if (parent.UITransactions.Remove(obj as UITransaction)) { - removed = true; - } - } + obj.GetType().IsSubclassOf(typeof(UITransaction))) { + report + .SystemObjectives + .SelectMany(x => + x.Objectives + .Where(x => x.UITransactions.Contains(obj as UITransaction)) + ) + .ToList() + .ForEach(x => removed = x.UITransactions.Remove(obj as UITransaction)) + ; } if (removed) {