private void Delete(TreeViewItem selectedNode, Source source) { if (selectedNode == null) { return; } if (selectedNode.Parent is TreeViewItem) { String customerName = (selectedNode.Parent as TreeViewItem).Header.ToString(); String carName; DateTime version; SplitNameVersion(selectedNode, out carName, out version); if (ShowConfirmDelete("car", selectedNode.Header.ToString())) { if (source == Source.DB ? db.DeleteCar(customerName, carName, version) : XmlParser.DeleteCar(customerName, carName, version)) { InitRest(); } else { MessageBox.Show("An error has occurred!"); } } } else { String customerName = selectedNode.Header.ToString(); if (ShowConfirmDelete("customer", customerName) && MessageBox.Show("Are you absolutely sure you want to delete this customer?\n All this customers cars will also be deleted!", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { if (source == Source.DB ? db.DeleteCustomer(customerName) : XmlParser.DeleteCustomer(customerName)) { InitRest(); } else { MessageBox.Show("An error has occurred!"); } } } }