private void ExecuteDeleteForeignAgentViewCommand() { try { if (SelectedAgent.Id == 1) { return;//can delete the last agent } if (MessageBox.Show("Are you Sure You want to Delete this Foreign Agent?", "Delete Foreign Agent", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.No) != MessageBoxResult.Yes) { return; } var ids = DbCommandUtil.QueryCommand("Select ForeignAgentId as Id from Visas " + " where Id='" + SelectedAgent.Id + "' and enabled='1'").ToList(); if (ids.Count == 0) { SelectedAgent.Enabled = false; _foreignAgentService.InsertOrUpdate(SelectedAgent); } else { MessageBox.Show("There may exist Visas Assigned to this agent, you have to update or delete " + "those Visas related with " + SelectedAgent.AgentName, "Can't Delete Agent", MessageBoxButton.OK, MessageBoxImage.Error); } } catch { MessageBox.Show("There may exist Visas Assigned to this agent, you have to update or delete those Visas related with " + SelectedAgent.AgentName, "Can't Delete Agent", MessageBoxButton.OK, MessageBoxImage.Error); } GetLiveForeignAgents(); }
private void ExecuteDeleteVisaViewCommand() { try { if (MessageBox.Show("Are you Sure You want to Delete this Visa?", "Delete Visa", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.No) != MessageBoxResult.Yes) { return; } //Check Constraints Before Deleting var ids = DbCommandUtil.QueryCommand("Select VisaId as Id from Employees " + " where Id='" + SelectedVisa.Id + "' and enabled='1'").ToList(); if (ids.Count == 0) { SelectedVisa.Enabled = false; _visaService.InsertOrUpdate(SelectedVisa); } else { MessageBox.Show("Problem deleting Visa, There may exist Employees Assigned to this Visa," + " you have to first update or delete those Employees related with " + SelectedVisa.VisaNumber, "Can't Delete Visa", MessageBoxButton.OK, MessageBoxImage.Error); } //Visas.Remove(SelectedVisa); } catch { MessageBox.Show( "Problem deleting Visa, There may exist Employees Assigned to this Visa, you have to first update or delete those Employees related with " + SelectedVisa.VisaNumber, "Can't Delete Visa", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ExecuteDeleteVisaViewCommand() { try { if (MessageBox.Show("Are you sure you want to delete this Visa?", "Delete Visa", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.No) != MessageBoxResult.Yes) { return; } //Check Constraints Before Deleting List <CommandModel> ids = DbCommandUtil.QueryCommand("Select VisaId as Id from Employees " + " where Id='" + SelectedVisa.Id + "' and enabled='1'").ToList(); if (ids.Count == 0) { SelectedVisa.Enabled = false; /**********/ SelectedVisa.Condition.Enabled = false; SelectedVisa.Sponsor.Enabled = false; SelectedVisa.Sponsor.Address.Enabled = false; /**********/ _visaService.InsertOrUpdate(SelectedVisa); Load(); } else { MessageBox.Show("Problem deleting Visa, There may exist Employees Assigned to this Visa," + " you have to first update or delete those Employees related with visa: " + SelectedVisa.VisaNumber, "Can't Delete Visa", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show("Problem deleting Visa, There may exist Employees Assigned to this Visa," + " you have to first update or delete those Employees related with " + SelectedVisa.VisaNumber + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, "Can't Delete Visa", MessageBoxButton.OK, MessageBoxImage.Error); } }