From 56d9346f9d34ceaf9d756d5d8d34e31f31f6b81e Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 18 Apr 2024 15:36:15 +0200 Subject: [PATCH] Avoid crash if delete is tried on deleted object --- src/BreCalClient/ShipListDialog.xaml.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/BreCalClient/ShipListDialog.xaml.cs b/src/BreCalClient/ShipListDialog.xaml.cs index 39bf3f1..e22d814 100644 --- a/src/BreCalClient/ShipListDialog.xaml.cs +++ b/src/BreCalClient/ShipListDialog.xaml.cs @@ -47,12 +47,15 @@ namespace BreCalClient { if (obj is ShipModel shipmodel) { - if(this.ShipApi != null) - await this.ShipApi.ShipDeleteAsync(shipmodel.Ship.Id); - BreCalLists.Ships.Remove(shipmodel); // remove from "selectable" ships - shipmodel.Ship.Deleted = true; // set deleted marker on working instance - this.dataGridShips.ItemsSource = null; - this.dataGridShips.ItemsSource = BreCalLists.AllShips; + if (!shipmodel.Ship.Deleted) + { + if (this.ShipApi != null) + await this.ShipApi.ShipDeleteAsync(shipmodel.Ship.Id); + BreCalLists.Ships.Remove(shipmodel); // remove from "selectable" ships + shipmodel.Ship.Deleted = true; // set deleted marker on working instance + this.dataGridShips.ItemsSource = null; + this.dataGridShips.ItemsSource = BreCalLists.AllShips; + } } }