public static void ConsolidateTopics(int toId, int fromId) { var politicians = Answers.GetAnswersForConsolidation(toId, fromId).Rows.OfType <DataRow>() .GroupBy(r => r.PoliticianKey(), StringComparer.OrdinalIgnoreCase); foreach (var politician in politicians) { // delete old Answers2.DeleteByPoliticianKeyQuestionId(politician.Key, toId); Answers2.DeleteByPoliticianKeyQuestionId(politician.Key, fromId); // insert new var answers = politician.OrderBy(r => IsNullOrWhiteSpace(r.YouTubeUrl()) ? r.AnswerDate() : r.YouTubeDate()); var sequence = 0; foreach (var a in answers) { Answers2.Insert(politician.Key, toId, sequence++, a.Answer(), a.Source(), a.DateStamp(), a.UserName(), a.YouTubeUrl(), a.YouTubeDescription(), a.YouTubeRunningTime(), a.YouTubeSource(), a.YouTubeSourceUrl(), a.YouTubeDate(), a.YouTubeRefreshTime(), a.YouTubeAutoDisable(), a.FacebookVideoUrl(), a.FacebookVideoDescription(), a.FacebookVideoRunningTime(), a.FacebookVideoDate(), a.FacebookVideoRefreshTime(), a.FacebookVideoAutoDisable()); } } // delete the topic Questions2.DeleteByQuestionId(fromId); IssuesQuestions.DeleteByQuestionId(fromId); }
private void UpdateDatabase() { // For now we just use a single Issue Group "Issues" // Create it, initially disabled DeleteNonPermanentIssueGroups(); IssueGroups2.Insert(issuesIssueGroupId, 10, false, "Issues", Empty); AppendStatusText("Global Issue Group created"); // Add the Issues DeleteNonPermanentIssues(); foreach (var kvp in _IssueDictionary) { Issues2.Insert(kvp.Value.IssueId, kvp.Value.IssueId, kvp.Value.Issue, false); } AppendStatusText($"{_IssueDictionary.Count} Issues created"); // Add the IssueGroupsIssues DeleteNonPermanentIssueGroupsIssues(); foreach (var kvp in _IssueDictionary) { IssueGroupsIssues2.Insert(issuesIssueGroupId, kvp.Value.IssueId, kvp.Value.IssueId); } AppendStatusText($"{_IssueDictionary.Count} IssueGroupsIssues created"); // Add the Questions DeleteNonPermanentQuestions(); foreach (var kvp in _TopicDictionary) { Questions2.Insert(kvp.Value.TopicId, kvp.Value.Topic, false); } AppendStatusText($"{_TopicDictionary.Count} Questions created"); // Add the QuestionJurisdictions // All are federal for now DeleteNonPermanentQuestionsJurisdictions(); foreach (var kvp in _TopicDictionary) { QuestionsJurisdictions.Insert(kvp.Value.TopicId, "B", Empty, Empty); } AppendStatusText($"{_TopicDictionary.Count} QuestionsJurisdictions created"); // Add the IssuesQuestions DeleteNonPermanentIssuesQuestions(); var iqCount = 0; foreach (var kvp in _IssueDictionary) { var value = kvp.Value; foreach (var topicId in value.TopicIds) { IssuesQuestions.Insert(value.IssueId, topicId, topicId); iqCount++; } } AppendStatusText($"{iqCount} IssuesQuestions created"); // remap existing answers RemapExistingAnswers(); }
protected void Page_Load(object sender, EventArgs e) { Master.NoHeading = true; MainBannerHomeLink.HRef = UrlManager.GetSiteUri().ToString(); Title = "Vote-USA - Manage Issue Responses"; if (UserSecurityClass != PoliticianSecurityClass) { var mainContent = Master.MainContentControl; mainContent.Controls.Clear(); new HtmlP { InnerText = "This page is only available to signed-in candidates" }.AddTo(mainContent, "user-error"); return; } PoliticianName.InnerText = base.PoliticianName; var issuesAndTopics = Questions2.GetIssuesAndTopics(); // prune to match the politician var liveOfficeKey = Politicians.GetLiveOfficeKey(PoliticianKey, Empty); var electoralClass = Offices.GetElectoralClass(Offices.GetOfficeClass(liveOfficeKey)); var stateCode = Offices.GetStateCodeFromKey(liveOfficeKey); var issueLevel = Empty; var countyOrLocal = Empty; switch (electoralClass) { case ElectoralClass.USPresident: case ElectoralClass.USSenate: case ElectoralClass.USHouse: issueLevel = "B"; break; case ElectoralClass.USGovernors: case ElectoralClass.State: issueLevel = "C"; break; case ElectoralClass.County: issueLevel = "D"; countyOrLocal = Offices.GetCountyCodeFromKey(liveOfficeKey); break; case ElectoralClass.Local: issueLevel = "E"; countyOrLocal = Offices.GetLocalKeyFromKey(liveOfficeKey); break; } foreach (var issue in issuesAndTopics) { foreach (var topic in issue.Questions) { if (topic.Jurisdictions.Any(j => j.IssueLevel == "A")) { topic.Pruned = false; } else { switch (issueLevel) { case "B": topic.Pruned = topic.Jurisdictions.All(j => j.IssueLevel != "B"); break; case "C": topic.Pruned = !topic.Jurisdictions.Any(j => j.IssueLevel == "C" && (j.StateCode == Empty || j.StateCode == stateCode)); break; case "D": topic.Pruned = !topic.Jurisdictions.Any(j => j.IssueLevel == "D" && (j.StateCode == Empty || j.StateCode == stateCode && (j.CountyOrLocal == Empty || j.CountyOrLocal == countyOrLocal))); break; case "E": topic.Pruned = !topic.Jurisdictions.Any(j => j.IssueLevel == "E" && (j.StateCode == Empty || j.StateCode == stateCode && (j.CountyOrLocal == Empty || j.CountyOrLocal == countyOrLocal))); break; default: topic.Pruned = true; break; } } } issue.Pruned = issue.Questions.All(q => q.Pruned); } var prunedIssuesAndTopics = issuesAndTopics.Where(i => !i.Pruned) .Select(i => new IssuesAndTopicsPrunedIssue { I = i.IssueId, Issue = i.Issue, Q = i.Questions.Where(q => !q.Pruned).Select(q => new IssuesAndTopicsPrunedQuestion { I = q.QuestionId, Q = q.Question }).ToList() }).ToList(); // load the topics var options = prunedIssuesAndTopics.Select(i => $"<option value=\"{i.I}\">{i.Issue}</option>"); IssuesSelectOptions.Text = "<option value=\"\">< select an issue ></option>" + Join(Empty, options); // second pruning to reduce bandwidth var rePrunedIssuesAndTopics = prunedIssuesAndTopics .Select(i => new IssuesAndTopicsRePrunedIssue { I = i.I, Q = i.Q }).ToList(); // make data available client side var body = Master.FindControl("body") as HtmlGenericControl; var json = new JavaScriptSerializer(); // ReSharper disable once PossibleNullReferenceException body.Attributes.Add("data-issues-and-topics", json.Serialize(rePrunedIssuesAndTopics)); body.Attributes.Add("data-politician-key", PoliticianKey); }