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); } }
private static void InvalidatePoliticianImage(string politicianKey) { // We do this via updates to avoid synchronization problems var oldBlobs = PoliticiansImagesBlobs.GetDataByPoliticianKey(politicianKey); if (oldBlobs.Count == 1) { var newBlobs = DB.Vote.PoliticiansImagesBlobs.GetCacheDataByPoliticianKey(politicianKey); switch (newBlobs.Count) { case 1: { var oldRow = oldBlobs[0]; var newRow = newBlobs[0]; oldRow.Profile300 = newRow.Profile300; oldRow.Profile200 = newRow.Profile200; oldRow.Headshot100 = newRow.Headshot100; oldRow.Headshot75 = newRow.Headshot75; oldRow.Headshot50 = newRow.Headshot50; oldRow.Headshot35 = newRow.Headshot35; oldRow.Headshot25 = newRow.Headshot25; oldRow.Headshot20 = newRow.Headshot20; oldRow.Headshot15 = newRow.Headshot15; PoliticiansImagesBlobs.UpdateTable(oldBlobs); } break; case 0: PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey); break; } } var oldData = PoliticiansImagesData.GetDataByPoliticianKey(politicianKey); if (oldData.Count != 1) { return; } var newData = DB.Vote.PoliticiansImagesData.GetDataByPoliticianKey(politicianKey); switch (newData.Count) { case 1: { var oldRow = oldData[0]; var newRow = newData[0]; //oldRow.ProfileOriginalContentType = newRow.ProfileOriginalContentType; oldRow.ProfileOriginalDate = newRow.ProfileOriginalDate; //oldRow.ProfileOriginalWidth = newRow.ProfileOriginalWidth; //oldRow.ProfileOriginalHeight = newRow.ProfileOriginalHeight; //oldRow.HeadshotContentType = newRow.HeadshotContentType; oldRow.HeadshotDate = newRow.HeadshotDate; //oldRow.HeadshotWidth = newRow.HeadshotWidth; //oldRow.HeadshotHeight = newRow.HeadshotHeight; oldRow.HeadshotResizeDate = newRow.HeadshotResizeDate; PoliticiansImagesData.UpdateTable(oldData); } break; case 0: PoliticiansImagesData.DeleteByPoliticianKey(politicianKey); break; } }