protected void ButtonEditPolitician_OnClick(object sender, EventArgs e) { var toEdit = GetPoliticianKeyToEdit(); var politicianKey = toEdit.Key; CandidateHtml.Controls.Clear(); var isRunningMate = !IsNullOrWhiteSpace(MainCandidateIfRunningMate.Value); if (Politicians.GetStateCodeFromKey(politicianKey) != "DC") { AddOnEditElement.AddCssClasses("hidden"); } switch (EditPoliticianReloading.Value) { case "reloading": { EditPoliticianReloading.Value = Empty; ControlEditPoliticianPartyKey.Items.Clear(); VotePage.LoadPartiesDropdown(Politicians.GetStateCodeFromKey(politicianKey), ControlEditPoliticianPartyKey, Empty, VotePage.PartyCategories.None, VotePage.PartyCategories.StateParties, VotePage.PartyCategories.NationalParties, VotePage.PartyCategories.NonParties); _EditPoliticianDialogInfo.LoadControls(); FeedbackEditPolitician.AddInfo("Politician information loaded."); var href = SecurePoliticianPage.GetUpdateIntroPageUrl(politicianKey); UpdateIntroLink.HRef = href; UpdateIntroLinkProfessional.HRef = href + "#bio2-ALLBio333333"; } break; case "": { // normal update _EditPoliticianDialogInfo.ClearValidationErrors(); _EditPoliticianDialogInfo.Update(FeedbackEditPolitician); var partyCodeToSuppress = Empty; if (isRunningMate) { partyCodeToSuppress = Parties.GetPartyCode( Politicians.GetPartyKey(MainCandidateIfRunningMate.Value)); } var row = Politicians.GetCandidateData(SafeGetElectionKey(), politicianKey, isRunningMate); // use current dynamic IsIncumbent row["IsIncumbent"] = toEdit.ShowAsIncumbent; CandidateHtml.Controls.Add(CreateCandidateEntry(row, Mode, partyCodeToSuppress, !isRunningMate && ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists( SafeGetElectionKey(), SafeGetOfficeKey(), politicianKey))); } break; default: throw new VoteException( $"Unknown reloading option: '{EditPoliticianReloading.Value}'"); } NameOnBallots.InnerText = PageCache.GetTemporary().Politicians .GetPoliticianName(politicianKey); UpdateIntroPage.SetPartyNameAndLink(ControlEditPoliticianPartyKey.GetValue(), PartyName); }
protected void ButtonSetupAd_OnClick(object sender, EventArgs e) { var politicianKey = AdSetupCandidate.Value; var electionKey = SafeGetElectionKey(); var officeKey = SafeGetOfficeKey(); CandidateAdName.InnerText = PageCache.GetTemporary().Politicians .GetPoliticianName(politicianKey); CandidateAdOffice.InnerText = Offices.FormatOfficeName(officeKey); CandidateAdElection.InnerText = PageCache.GetTemporary().Elections .GetElectionDesc(electionKey); CandidateAdRate.InnerText = Offices.GetAdRate(electionKey, officeKey) .ToString("C", CultureInfo.CreateSpecificCulture("en-US")); switch (SetupAdReloading.Value) { case "reloading": { SetupAdReloading.Value = Empty; _SetupAdDialogInfo.LoadControls(); FeedbackSetupAd.AddInfo("Ad information loaded."); var urlItem = _SetupAdDialogInfo.First(i => i.Column == "AdUrl"); var videoUrl = urlItem.DataControl.GetValue(); if (IsNullOrWhiteSpace(videoUrl)) { videoUrl = DefaultAdVideo.Value = PageCache.GetTemporary().Politicians .GetYouTubeWebAddress(politicianKey); } else { DefaultAdVideo.Value = Empty; } SetupSampleAd(electionKey, officeKey, politicianKey, videoUrl); } break; case "": { // normal update _SetupAdDialogInfo.ClearValidationErrors(); DefaultAdVideo.Value = Empty; // handle default date var dateItem = _SetupAdDialogInfo.First(i => i.Column == "AdTimeStamp"); if (IsNullOrWhiteSpace(dateItem.DataControl.GetValue())) { dateItem.DataControl.SetValue(DateTime.UtcNow.ToShortDateString()); } var adTypeItem = _SetupAdDialogInfo.First(i => i.Column == "AdType"); var urlItem = _SetupAdDialogInfo.First(i => i.Column == "AdUrl"); var thumbItem = _SetupAdDialogInfo.First(i => i.Column == "AdThumbnailUrl"); switch (adTypeItem.DataControl.GetValue()) { case "Y": // YouTube // make sure we have a thumbnail video if main URL is not a video var videoUrl = urlItem.DataControl.GetValue(); if (!videoUrl.IsValidYouTubeVideoUrl()) { var thumbUrl = thumbItem.DataControl.GetValue(); if (IsNullOrWhiteSpace(thumbUrl)) { FeedbackSetupAd.PostValidationError(thumbItem.DataControl, "Thumbnail URL is required for channels or playlists"); } } // clear the image name var adImageNameItem = _SetupAdDialogInfo.First(i => i.Column == "AdImageName"); adImageNameItem.DataControl.SetValue(Empty); break; case "I": // image // clear the video and thumbnail urlItem.DataControl.SetValue(Empty); thumbItem.DataControl.SetValue(Empty); break; } _SetupAdDialogInfo.Update(FeedbackSetupAd); ControlSetupAdAdImageUpdated.Text = "False"; if (FeedbackSetupAd.ValidationErrorCount == 0) { SetupSampleAd(electionKey, officeKey, politicianKey); } } break; default: throw new VoteException( $"Unknown reloading option: '{EditPoliticianReloading.Value}'"); } }
public static PageCache GetPageCache() { var votePage = GetPage <VotePage>(); return(votePage == null?PageCache.GetTemporary() : votePage.PageCache); }
private void SetupSampleAd(string electionKey, string officeKey, string politicianKey, string videoUrl = null) { SampleAd.Visible = false; VideoWrapper.Visible = false; ImageWrapper.Visible = false; var adTypeItem = _SetupAdDialogInfo.First(i => i.Column == "AdType"); switch (adTypeItem.DataControl.GetValue()) { case "Y": // YouTube VideoWrapper.Visible = true; if (IsNullOrWhiteSpace(videoUrl)) { var urlItem = _SetupAdDialogInfo.First(i => i.Column == "AdUrl"); videoUrl = urlItem.DataControl.GetValue(); } if (IsNullOrWhiteSpace(videoUrl)) { return; } string thumbId; if (videoUrl.IsValidYouTubeVideoUrl()) { thumbId = videoUrl.GetYouTubeVideoId(); } else { var thumbItem = _SetupAdDialogInfo.First(i => i.Column == "AdThumbnailUrl"); var thumbUrl = thumbItem.DataControl.GetValue(); if (IsNullOrWhiteSpace(thumbUrl)) { return; } thumbId = thumbUrl.GetYouTubeVideoId(); } if (IsNullOrWhiteSpace(thumbId)) { return; } SampleThumb.Src = $"http://i.ytimg.com/vi/{thumbId}/hqdefault.jpg"; break; case "I": // Image ImageWrapper.Visible = true; var website = Politicians.GetPublicWebAddress(politicianKey); //if (IsNullOrWhiteSpace(website)) return; //ImageLink.HRef = VotePage.NormalizeUrl(website); //AdImage.Src = UrlManager // .GetSiteUri("adimage", $"{electionKey}.{officeKey}.{politicianKey}.{DateTime.UtcNow.Ticks}").ToString(); if (IsNullOrWhiteSpace(website)) { ImageLink.Attributes.Remove("href"); } else { ImageLink.HRef = VotePage.NormalizeUrl(website); } AdImage.Src = UrlManager .GetSiteUri("adimage", $"{electionKey}.{officeKey}.{politicianKey}.{DateTime.UtcNow.Ticks}").ToString(); break; } var sponsor = _SetupAdDialogInfo.First(i => i.Column == "AdSponsor").DataControl.GetValue(); var sponsorUrl = _SetupAdDialogInfo.First(i => i.Column == "AdSponsorUrl").DataControl.GetValue(); var isCandidateSponsored = _SetupAdDialogInfo.First(i => i.Column == "AdIsCandidateSponsored").DataControl.GetValue() == "True"; var paidMessage = new PlaceHolder(); if (isCandidateSponsored) { var url = IsNullOrWhiteSpace(sponsorUrl) ? SecurePoliticianPage.GetPoliticianPublicPageUrl("intro", politicianKey) : VotePage.NormalizeUrl(sponsorUrl); new LiteralControl("Paid advertisement by ").AddTo(paidMessage); new HtmlBreak().AddTo(paidMessage); new HtmlAnchor { HRef = url, Target = "_blank", InnerHtml = "candidate’s campaign" }.AddTo(paidMessage); } else if (!IsNullOrWhiteSpace(sponsor)) { if (IsNullOrWhiteSpace(sponsorUrl)) { new LiteralControl("Paid advertisement by ").AddTo(paidMessage); new HtmlBreak().AddTo(paidMessage); new LiteralControl($"{sponsor}").AddTo(paidMessage); } else { new LiteralControl("Paid advertisement by ").AddTo(paidMessage); new HtmlBreak().AddTo(paidMessage); new HtmlAnchor { HRef = VotePage.NormalizeUrl(sponsorUrl), Target = "_blank", InnerText = sponsor }.AddTo(paidMessage); } } else { new LiteralControl("Paid advertisement").AddTo(paidMessage); } SampleAd.Visible = true; SampleName.InnerText = PageCache.GetTemporary().Politicians .GetPoliticianName(politicianKey); SampleProfile.Src = VotePage.GetPoliticianImageUrl(politicianKey, "Headshot100"); PaidAdvertisement.Controls.Clear(); PaidAdvertisement.Controls.Add(paidMessage); ComparePageLink.HRef = $"{UrlManager.GetCompareCandidatesPageUri(electionKey, officeKey)}" + $"&ad={politicianKey}"; }