public override void CanClose(Action <bool> callback) { if (isCanceling) { callback?.Invoke(true); } else if (string.IsNullOrWhiteSpace(rifle?.Name)) { MessageBox.Show("Please fill out rifle name before saving", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else if (rifle.Cartridge == null || rifle.Scope == null) { MessageBox.Show("Please select a cartridge and scope before saving (perhaps you need to define them before configuring a rifle)", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else if (cartridgesModel.ByName(rifle.Cartridge.Name) == null) { MessageBox.Show("This rifle is using unlisted (deleted?) cartridge, please select one that is listed", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else if (scopesModel.ByName(rifle.Scope.Name) == null) { MessageBox.Show("This rifle is using unlisted (deleted?) scope, please select one that is listed", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else if (HasErrors && !isCanceling) { if (rifle != null && rifle.BarrelTwist.As(LengthUnit.Inch) <= 0) { MessageBox.Show("Please make sure that barrel twist is higher than zero before saving", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { MessageBox.Show("Please fill-out all fields for the rifle before saving", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); } callback?.Invoke(false); } else { callback?.Invoke(true); } }
public override void CanClose(Action <bool> callback) { var scopeWithTheSameName = scopesModel.ByName(scope.Name); if (scopeWithTheSameName != null && !isCanceling && isNew) { MessageBox.Show("Scope with the same name already exists.", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else if (HasErrors && !isCanceling) { MessageBox.Show("Please fill-out all fields for the scope before saving", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); callback?.Invoke(false); } else { callback?.Invoke(true); } }