Avoid crash if delete is tried on deleted object

This commit is contained in:
Daniel Schick 2024-04-18 15:36:15 +02:00
parent 75585153d4
commit bedf68c4d5

View File

@ -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;
}
}
}