protected void ButtonAddCandidates_OnClick(object sender, EventArgs e) { switch (AddCandidatesReloading.Value) { case "reloading": { DeletePoliticianOverrideContainer.AddCssClasses("hidden"); DeletePoliticianOverride.Checked = false; AddCandidatesReloading.Value = Empty; _ManagePoliticiansPanel.LoadControls(); _ManagePoliticiansPanel.ClearAddNewCandidate(true); break; } case "deleting": { AddCandidatesReloading.Value = Empty; DeletePoliticianOverrideContainer.AddCssClasses("hidden"); var keyToDelete = AddCandidatesKeyToDelete.GetValue(); // check for meaningful usages var referenceList = new List <string>(); FormatReferences(referenceList, "Answers", Answers2.CountByPoliticianKey(keyToDelete)); FormatReferences(referenceList, "ElectionsPoliticians", ElectionsPoliticians.CountByPoliticianKey(keyToDelete)); FormatReferences(referenceList, "ElectionsPoliticians:RunningMateKey", ElectionsPoliticians.CountByRunningMateKey(keyToDelete)); FormatReferences(referenceList, "OfficesOfficials", OfficesOfficials.CountByPoliticianKey(keyToDelete)); FormatReferences(referenceList, "OfficesOfficials:RunningMateKey", OfficesOfficials.CountByRunningMateKey(keyToDelete)); if (referenceList.Count > 0 && !DeletePoliticianOverride.Checked) { FeedbackAddCandidates.AddError( "Cannot delete because the PoliticianKey is referenced in the following tables. Check the box to override."); DeletePoliticianOverrideContainer.RemoveCssClass("hidden"); foreach (var @ref in referenceList) { FeedbackAddCandidates.AddError(@ref); } return; } // delete DeletePoliticianOverride.Checked = false; var name = PageCache.Politicians.GetPoliticianName(keyToDelete); if (referenceList.Count > 0) { DeleteAllPoliticianReferences(keyToDelete); } Politicians.DeleteByPoliticianKey(keyToDelete); FeedbackAddCandidates.AddInfo($"Politician {name} ({keyToDelete}) deleted."); AddCandidatesKeyToDelete.Value = Empty; //_DeleteDistrictsTabInfo.ClearValidationErrors(); //PopulateLocalDistrictDropdown(); //_DeleteDistrictsTabInfo.LoadControls(); break; } case "": { //// normal update //_ManagePoliticiansPanel.Update(); //_ManagePoliticiansPanel.ClearAddNewCandidate(); break; } default: throw new VoteException($"Unknown reloading option: '{AddCandidatesReloading.Value}'"); } }