protected override bool Update(object newValue) { var changed = false; //Parse the value from the UI tree var valueStr = newValue as string; if (valueStr == null) { return(false); } var offices = valueStr.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(officeStr => { var officeSplit = officeStr.Split(':'); return (new { OfficeKey = officeSplit[0], Incumbents = officeSplit[1].Split(',') }); }) .ToArray(); foreach (var office in offices) { var table = OfficesOfficials.GetDataByOfficeKey(office.OfficeKey); var officeChanged = false; foreach (var row in table) { if (!office.Incumbents.Contains(row.PoliticianKey)) { if (!ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists (Page.GetElectionKey(), row.OfficeKey, row.PoliticianKey)) { ElectionsIncumbentsRemoved.Insert(Page.GetElectionKey(), row.OfficeKey, row.PoliticianKey, row.RunningMateKey, row.StateCode, row.CountyCode, row.LocalCode, row.DistrictCode, //row.LDSVersion, row.LDSUpdateDate, row.DataLastUpdated, row.UserSecurity, row.UserName); } row.Delete(); officeChanged = true; } } if (!officeChanged) { continue; } OfficesOfficials.UpdateTable(table); changed = true; } //LoadControl(); return(changed); }
private static void DeleteAllPoliticianReferences(string politicianKey) { Answers2.DeleteByPoliticianKey(politicianKey); ElectionsIncumbentsRemoved.DeleteByPoliticianKey(politicianKey); ElectionsIncumbentsRemoved.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); ElectionsPoliticians.DeleteByPoliticianKey(politicianKey); ElectionsPoliticians.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); OfficesOfficials.DeleteByPoliticianKey(politicianKey); OfficesOfficials.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey); PoliticiansImagesData.DeleteByPoliticianKey(politicianKey); TempEmail.DeleteByPoliticianKey(politicianKey); }
private static void DeleteAllDistictReferences(string stateCode, string localKey) { Elections.DeleteByStateCodeLocalKey(stateCode, localKey); ElectionsIncumbentsRemoved.DeleteByStateCodeLocalKey(stateCode, localKey); ElectionsOffices.DeleteByStateCodeLocalKey(stateCode, localKey); ElectionsPoliticians.DeleteByStateCodeLocalKey(stateCode, localKey); QuestionsJurisdictions.DeleteByIssueLevelStateCodeCountyOrLocal(Issues.IssueLevelLocal, stateCode, localKey); Offices.DeleteByStateCodeLocalKey(stateCode, localKey); //OfficesAllIdentified.DeleteByStateCodeLocalKey(stateCode, localKey); OfficesOfficials.DeleteByStateCodeLocalKey(stateCode, localKey); Referendums.DeleteByStateCodeLocalKey(stateCode, localKey); }
protected override bool Update(object newValue) { var changed = false; //Parse the value from the UI tree if (!(newValue is string valueStr)) { return(false); } var offices = valueStr.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(officeStr => { var officeSplit = officeStr.Split(':'); return(new { OfficeKey = officeSplit[0], Incumbents = officeSplit[1].Split(',') }); }).ToArray(); foreach (var office in offices) { foreach (var incumbent in office.Incumbents) { var table = ElectionsIncumbentsRemoved.GetDataByElectionKeyOfficeKeyPoliticianKey( Page.GetElectionKey(), office.OfficeKey, incumbent); if (table.Count == 1) { var row = table[0]; changed = true; if (!OfficesOfficials.OfficeKeyPoliticianKeyExists(row.OfficeKey, row.PoliticianKey)) { OfficesOfficials.Insert(row.OfficeKey, row.PoliticianKey, row.RunningMateKey, row.StateCode, Offices.GetCountyCodeFromKey(row.OfficeKey), Offices.GetLocalKeyFromKey(row.OfficeKey), row.DistrictCode, row.DataLastUpdated, row.UserSecurity, row.UserName); } ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey( Page.GetElectionKey(), office.OfficeKey, incumbent); } } } //LoadControl(); return(changed); }
public override void LoadControl() { var incumbentsToReinstate = ElectionsIncumbentsRemoved.GetOfficesWithCandidatesToReinstate( Page.GetElectionKey()); Page.ControlAdjustIncumbentsReinstatementListValue.Value = string.Empty; if (incumbentsToReinstate.Count == 0) { Page.ReinstateIncumbentsMessage.AddCssClasses("hidden"); Page.ReinstateIncumbentsControl.AddCssClasses("hidden"); } else { Page.ReinstateIncumbentsMessage.RemoveCssClass("hidden"); Page.ReinstateIncumbentsControl.RemoveCssClass("hidden"); PopulateIncumbentsToReinstateList(incumbentsToReinstate, Page.PlaceHolderReinstateIncumbentsList); } }
private void Consolidate() { try { var key1Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key1"); var key2Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key2"); var jurisdictionKey = JurisdictionalKey; var success = true; success &= DataItemBase.ValidateRequired(key1Item); var key1Office = key1Item.DataControl.GetValue().Trim(); success &= DataItemBase.ValidateRequired(key2Item); var key2Office = key2Item.DataControl.GetValue().Trim(); if (success && key1Office.IsEqIgnoreCase(key2Office)) { key2Item.Feedback.PostValidationError(key2Item.DataControl, key2Item.Description + " is identical to " + key1Item.Description); success = false; } var officeKey1 = jurisdictionKey + key1Office; var officeKey2 = jurisdictionKey + key2Office; if (!success) { return; } // do the consolidation var updateCount = 0; if (Offices.OfficeKeyExists(officeKey1)) { updateCount += Offices.DeleteByOfficeKey(officeKey2); } else { updateCount += Offices.UpdateOfficeKey(officeKey1, officeKey2); } foreach (var row in ElectionsOffices.GetDataByOfficeKey(officeKey2)) { if (ElectionsOffices.ElectionKeyOfficeKeyExists(row.ElectionKey, officeKey1)) { updateCount += ElectionsOffices.DeleteByElectionKeyOfficeKey(row.ElectionKey, officeKey2); } else { updateCount += ElectionsOffices.UpdateOfficeKeyByElectionKeyOfficeKey(officeKey1, row.ElectionKey, officeKey2); } } foreach (var row in ElectionsPoliticians.GetDataByOfficeKey(officeKey2)) { if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsPoliticians.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsPoliticians.UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } foreach (var row in OfficesOfficials.GetDataByOfficeKey(officeKey2)) { if (OfficesOfficials.OfficeKeyPoliticianKeyExists(officeKey1, row.PoliticianKey)) { updateCount += OfficesOfficials.DeleteByOfficeKeyPoliticianKey(officeKey2, row.PoliticianKey); } else { updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKeyPoliticianKey(officeKey1, officeKey2, row.PoliticianKey); } } foreach (var row in ElectionsIncumbentsRemoved.GetDataByOfficeKey(officeKey2)) { if (ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsIncumbentsRemoved .UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } updateCount += Politicians.UpdateOfficeKeyByOfficeKey(officeKey1, officeKey2); var msg = $"{updateCount} instances of the second office key {officeKey2} were found."; if (updateCount > 0) { msg += $" They were all changed to the first office key {officeKey1}."; } FeedbackMasterOnly.AddInfo(msg); ResetMasterOnlySubTab(MasterOnlySubTab.Consolidate); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey, "The office keys could not be consolidated: " + ex.Message); } }
private void ChangeOfficeKey() { try { var oldKeyItem = _MasterOnlyTabInfo.Single(i => i.Column == "OldKey"); var newKeyItem = _MasterOnlyTabInfo.Single(i => i.Column == "NewKey"); var jurisdictionKey = JurisdictionalKey; var success = true; success &= DataItemBase.ValidateRequired(oldKeyItem); var oldKeyOffice = oldKeyItem.DataControl.GetValue().Trim(); success &= DataItemBase.ValidateRequired(newKeyItem); var newKeyOffice = newKeyItem.DataControl.GetValue().Trim(); if (!string.IsNullOrWhiteSpace(newKeyOffice)) { // get rid of all non-alphanumerics newKeyOffice = Regex.Replace(newKeyOffice, @"[^\dA-Z]", string.Empty, RegexOptions.IgnoreCase); // get rid of leading numerics newKeyOffice = Regex.Replace(newKeyOffice, @"^\d+", string.Empty); var maxLength = Offices.OfficeKeyMaxLength - jurisdictionKey.Length; if (newKeyOffice.Length > maxLength) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " is too long by " + (newKeyOffice.Length - maxLength) + " characters."); success = false; } if (newKeyOffice.Length == 0) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " consists entirely of non-key characters."); success = false; } } if (success && (oldKeyOffice == newKeyOffice)) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " is identical to the Old Office Key."); success = false; } var oldOfficeKey = jurisdictionKey + oldKeyOffice; var newOfficeKey = jurisdictionKey + newKeyOffice; var caseChangeOnly = oldOfficeKey.IsEqIgnoreCase(newOfficeKey); if (success && !caseChangeOnly) { // Make sure the new office key doesn't already exist var existsInTables = new List <string>(); if (Offices.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(Offices.TableName); } if (ElectionsOffices.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsOffices.TableName); } if (ElectionsPoliticians.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsPoliticians.TableName); } if (OfficesOfficials.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(OfficesOfficials.TableName); } if (ElectionsIncumbentsRemoved.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(ElectionsIncumbentsRemoved.TableName); } if (Politicians.OfficeKeyExists(newOfficeKey)) { existsInTables.Add(Politicians.TableName); } if (existsInTables.Count > 0) { newKeyItem.Feedback.PostValidationError(newKeyItem.DataControl, newKeyItem.Description + " already exists in the following tables: " + string.Join(", ", existsInTables)); success = false; } } if (!success) { return; } // do the replacement var updateCount = 0; updateCount += Offices.UpdateOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsOffices.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsPoliticians.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += ElectionsIncumbentsRemoved.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); updateCount += Politicians.UpdateOfficeKeyByOfficeKey(newOfficeKey, oldOfficeKey); var msg = $"{updateCount} instances of the old office key {oldOfficeKey} were found."; if (updateCount > 0) { msg += $" They were all changed to the new office key {newOfficeKey}."; } FeedbackMasterOnly.AddInfo(msg); ResetMasterOnlySubTab(MasterOnlySubTab.ChangeKey); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey, "The office key could not be changed: " + ex.Message); } }
private void DoConsolidation() { try { var selectedIndex = ConsolidateSelectedIndex.Value; string selectedKey; string unselectedKey; switch (selectedIndex) { case "1": selectedKey = ConsolidateKey1.Value; unselectedKey = ConsolidateKey2.Value; break; case "2": selectedKey = ConsolidateKey2.Value; unselectedKey = ConsolidateKey1.Value; break; default: throw new VoteException("Index not 1 or 2"); } //throw new VoteException("An error"); // Politicians var selectedPolitician = Politicians.GetData(selectedKey); var unselectedPolitician = Politicians.GetData(unselectedKey); if (selectedPolitician.Count != 1) { throw new VoteException("Politician " + selectedPolitician + " not found"); } if (unselectedPolitician.Count != 1) { throw new VoteException("Politician " + unselectedKey + " not found"); } var selectedData = UpdatePoliticians(selectedIndex, selectedPolitician, unselectedPolitician); // PoliticiansImagesData and PoliticiansImagesBlobs var selectedImagesData = PoliticiansImagesData.GetData(selectedKey); var unselectedImagesData = PoliticiansImagesData.GetData(unselectedKey); var selectedImagesBlobs = PoliticiansImagesBlobs.GetData(selectedKey); var unselectedImagesBlobs = PoliticiansImagesBlobs.GetData(unselectedKey); UpdateImages(selectedIndex, selectedData, selectedKey, selectedImagesData, selectedImagesBlobs, unselectedImagesData, unselectedImagesBlobs); // Answers var selectedAnswers = Answers.GetActiveDataByPoliticianKey(selectedKey); var unselectedAnswers = Answers.GetDataByPoliticianKey(unselectedKey); UpdateAnswers(selectedKey, selectedAnswers, unselectedAnswers); // ElectionsIncumbentsRemoved var selectedIncumbentsRemoved = ElectionsIncumbentsRemoved.GetDataByPoliticianKey(selectedKey); var unselectedIncumbentsRemoved = ElectionsIncumbentsRemoved.GetDataByPoliticianKey(unselectedKey); UpdateIncumbentsRemoved(selectedKey, unselectedIncumbentsRemoved, selectedIncumbentsRemoved); // ElectionsPoliticians var selectedElectionsPoliticians = ElectionsPoliticians.GetDataByPoliticianKey(selectedKey); var unselectedElectionsPoliticians = ElectionsPoliticians.GetDataByPoliticianKey(unselectedKey); UpdateElectionsPoliticians(selectedKey, unselectedElectionsPoliticians, selectedElectionsPoliticians); // OfficesOfficials var selectedOfficesOfficials = OfficesOfficials.GetDataByPoliticianKey(selectedKey); var unselectedOfficesOfficials = OfficesOfficials.GetDataByPoliticianKey(unselectedKey); UpdateOfficesOfficials(selectedKey, unselectedOfficesOfficials, selectedOfficesOfficials); // Update everything as one transaction, politicians last PoliticiansImagesData.UpdateTable(selectedImagesData); PoliticiansImagesData.UpdateTable(unselectedImagesData); PoliticiansImagesBlobs.UpdateTable(selectedImagesBlobs); PoliticiansImagesBlobs.UpdateTable(unselectedImagesBlobs); Answers.UpdateTable(selectedAnswers); Answers.UpdateTable(unselectedAnswers); ElectionsIncumbentsRemoved.UpdateTable(unselectedIncumbentsRemoved); ElectionsPoliticians.UpdateTable(unselectedElectionsPoliticians); OfficesOfficials.UpdateTable(unselectedOfficesOfficials); Politicians.UpdateTable(selectedPolitician); Politicians.UpdateTable(unselectedPolitician); // Log LogDataChange.LogUpdate("*ConsolidatePoliticians", "*Various", unselectedKey, selectedKey, VotePage.UserName, SecurePage.UserSecurityClass, DateTime.UtcNow, selectedKey); // After the main update, refresh the LiveOfficeKey, LiveOfficeStatus and LiveElectionKey var view = PoliticiansLiveOfficeKeyView.GetData(selectedKey); if (view.Count == 1) { var keyAndStatus = PoliticianOfficeStatus.FromLiveOfficeKeyAndStatus( view[0].LiveOfficeKeyAndStatus); selectedPolitician[0].LiveOfficeKey = keyAndStatus.OfficeKey; selectedPolitician[0].LiveOfficeStatus = keyAndStatus.PoliticianStatus.ToString(); selectedPolitician[0].LiveElectionKey = keyAndStatus.ElectionKey; Politicians.UpdateTable(selectedPolitician); } ConsolidateReloaded.Value = "ok"; } catch (Exception ex) { FeedbackConsolidate.AddError("There was an unexpected error: " + ex.Message); } }