protected void ButtonSignin_Click(object sender, EventArgs e) { try { bool success; FeedbackContainerControl.ClearValidationErrors( TextBoxUserName, TextBoxPassword); SignInFeedback.ValidateRequired(TextBoxUserName, "Username", out success); SignInFeedback.ValidateRequired(TextBoxPassword, "Password", out success); if (SignInFeedback.ValidationErrorCount != 0) { return; } var usernameEntered = TextBoxUserName.Text.Trim(); var passwordEntered = TextBoxPassword.Text.Trim(); HandleSignin(usernameEntered, passwordEntered); } catch (VoteException ex) { SignInFeedback.AddError(ex.Message); } catch (Exception ex) { SignInFeedback.AddError("Your signin failed due to an unexpected error."); SignInFeedback.HandleException(ex); } }
private SecurePage.UpdateStatus DoAnswerUpdate(IList <IGrouping <string, AnswersViewRow> > table, string questionKey, bool reportUnchanged, ref int updateCount) { var page = VotePage.GetPage <SecurePoliticianPage>(); var updateStatus = SecurePage.UpdateStatus.Failure; // default var description = string.Empty; var feedback = page.Master.FindMainContentControl("Feedback" + questionKey) as FeedbackContainerControl; var updatePanel = page.Master.FindMainContentControl("UpdatePanel" + questionKey) as UpdatePanel; var textAnswerBox = page.Master.FindMainContentControl("TextBox" + questionKey) as TextBox; var textSourceBox = page.Master.FindMainContentControl("Source" + questionKey) as TextBox; var textDateBox = page.Master.FindMainContentControl("Date" + questionKey) as TextBox; var youTubeUrlBox = page.Master.FindMainContentControl("YouTubeUrl" + questionKey) as TextBox; var youTubeSourceBox = page.Master.FindMainContentControl("YouTubeSource" + questionKey) as TextBox; var youTubeSourceUrlBox = page.Master.FindMainContentControl("YouTubeSourceUrl" + questionKey) as TextBox; var youTubeDateBox = page.Master.FindMainContentControl("YouTubeDate" + questionKey) as TextBox; var youTubeDescriptionBox = page.Master.FindMainContentControl("YouTubeDescription" + questionKey) as TextBox; var youTubeRunningTimeBox = page.Master.FindMainContentControl("YouTubeRunningTime" + questionKey) as TextBox; var youTubeFromCandidate = page.Master.FindMainContentControl("YouTubeFromCandidate" + questionKey) as HtmlInputCheckBox; var youTubeFromVoteUsa = page.Master.FindMainContentControl("YouTubeFromVoteUSA" + questionKey) as HtmlInputCheckBox; var sequenceHidden = page.Master.FindMainContentControl("Sequence" + questionKey) as HtmlInputHidden; var hasValue = page.Master.FindMainContentControl("HasValue" + questionKey) as HtmlInputHidden; var textIsFromCandidate = SecurePage.IsPoliticianUser; var youTubeIsFromCandidate = SecurePage.IsPoliticianUser || youTubeFromCandidate.Checked || youTubeSourceBox.Text.Trim() == YouTubeInfo.VideoUploadedByCandidateMessage; try { textAnswerBox.AddCssClasses("badupdate"); FeedbackContainerControl.ClearValidationErrors(textAnswerBox, textSourceBox, textDateBox, youTubeUrlBox, youTubeDateBox); var sequence = sequenceHidden.Value == "?" ? Answers.GetNextSequence(page.PoliticianKey, questionKey) : int.Parse(sequenceHidden.Value); var newTextAnswer = textAnswerBox.GetValue(); string newTextSource; DateTime newTextDate; var newYouTubeSource = string.Empty; var newYouTubeSourceUrl = string.Empty; var newYouTubeDate = VotePage.DefaultDbDate; bool success; var textDateWasEmpty = true; var youTubeDateWasEmpty = true; youTubeDescriptionBox.Text = string.Empty; youTubeRunningTimeBox.Text = string.Empty; newTextAnswer = feedback.StripHtml(newTextAnswer); newTextAnswer = newTextAnswer.StripRedundantSpaces(); var oldResponses = table.Where(g => g.Key.IsEqIgnoreCase(questionKey)) .SelectMany(g => g); var question = oldResponses.First(); var oldRow = table.Where(g => g.Key.IsEqIgnoreCase(questionKey)) .SelectMany(g => g) .FirstOrDefault(r => r.Sequence == sequence); description = '"' + question.Question + '"'; var isAnswerChanged = oldRow == null || /*newTextAnswer*/ textAnswerBox.GetValue().Trim() != oldRow.Answer.Trim(); if (string.IsNullOrWhiteSpace(newTextAnswer)) { newTextSource = string.Empty; newTextDate = VotePage.DefaultDbDate; } else if (textIsFromCandidate) { newTextSource = page.PageCache.Politicians.GetLastName(page.PoliticianKey); newTextDate = DateTime.UtcNow.Date; } else { newTextSource = textSourceBox.Text; newTextSource = feedback.StripHtml(newTextSource); newTextSource = newTextSource.StripRedundantSpaces(); textDateWasEmpty = string.IsNullOrWhiteSpace(textDateBox.Text); newTextDate = feedback.ValidateDateOptional(textDateBox, out success, "Text Date", isAnswerChanged ? DateTime.UtcNow.Date : VotePage.DefaultDbDate) .Date; } var newYouTubeUrl = youTubeUrlBox.GetValue(); newYouTubeUrl = feedback.StripHtml(newYouTubeUrl); newYouTubeUrl = newYouTubeUrl.StripRedundantSpaces(); YouTubeInfo youTubeInfo = null; if (!string.IsNullOrWhiteSpace(newYouTubeUrl)) { var youTubeId = newYouTubeUrl.GetYouTubeVideoId(); if (youTubeFromCandidate != null && !youTubeFromCandidate.Checked && youTubeFromVoteUsa != null && !youTubeFromVoteUsa.Checked) { feedback.PostValidationError(new[] { youTubeFromCandidate, youTubeFromVoteUsa }, "Please select a type of video"); } if (string.IsNullOrWhiteSpace(youTubeId)) { feedback.PostValidationError(youTubeUrlBox, YouTubeInfo.InvalidVideoUrlMessage); } else { youTubeInfo = YouTubeUtility.GetVideoInfo(youTubeId, true, 1); if (!youTubeInfo.IsValid) { feedback.PostValidationError(youTubeUrlBox, YouTubeInfo.VideoIdNotFoundMessage); } else if (!youTubeInfo.IsPublic) { feedback.PostValidationError(youTubeUrlBox, YouTubeInfo.VideoNotPublicMessage); } else { youTubeDateWasEmpty = string.IsNullOrWhiteSpace(youTubeDateBox?.Text); if (youTubeIsFromCandidate) { newYouTubeSource = YouTubeInfo.VideoUploadedByCandidateMessage; newYouTubeSourceUrl = string.Empty; newYouTubeDate = youTubeInfo.PublishedAt; } else { newYouTubeSource = youTubeSourceBox.Text; newYouTubeSource = feedback.StripHtml(newYouTubeSource); newYouTubeSource = newYouTubeSource.StripRedundantSpaces(); newYouTubeSourceUrl = youTubeSourceUrlBox == null ? string.Empty : youTubeSourceUrlBox.Text; newYouTubeSourceUrl = feedback.StripHtml(newYouTubeSourceUrl); newYouTubeSourceUrl = Validation.StripWebProtocol(newYouTubeSourceUrl); newYouTubeDate = youTubeDateWasEmpty ? youTubeInfo.PublishedAt : feedback.ValidateDate(youTubeDateBox, out success, "YouTube Date", new DateTime(2004, 1, 1), DateTime.UtcNow).Date; } } } } if (feedback.ValidationErrorCount == 0) { var oldTextAnswer = string.Empty; var oldTextSource = string.Empty; var oldTextDate = VotePage.DefaultDbDate; var oldYouTubeUrl = string.Empty; var oldYouTubeSource = string.Empty; var oldYouTubeSourceUrl = string.Empty; var oldYouTubeDate = VotePage.DefaultDbDate; if (oldRow != null) { oldTextAnswer = oldRow.Answer.SafeString(); oldTextSource = oldRow.Source.SafeString(); oldTextDate = oldRow.DateStamp.SafeDbDate(); oldYouTubeUrl = oldRow.YouTubeUrl.SafeString(); oldYouTubeSource = oldRow.YouTubeSource(); oldYouTubeSourceUrl = oldRow.YouTubeSourceUrl().SafeString(); oldYouTubeDate = oldRow.YouTubeDate.SafeDbDate() .Date; } var unchanged = oldTextAnswer == newTextAnswer && oldYouTubeUrl == newYouTubeUrl && oldYouTubeSource == newYouTubeSource && oldYouTubeSourceUrl == newYouTubeSourceUrl && (oldYouTubeDate == newYouTubeDate || youTubeDateWasEmpty); if (unchanged && !textIsFromCandidate) { unchanged = oldTextSource == newTextSource && (oldTextDate == newTextDate || textDateWasEmpty); } if (unchanged) { if (reportUnchanged) { feedback.AddInfo("Your " + description + " entry was unchanged."); updatePanel.Update(); } updateStatus = SecurePage.UpdateStatus.Unchanged; } else { if (!textIsFromCandidate && !question.IsTextSourceOptional.GetValueOrDefault() && !string.IsNullOrWhiteSpace(newTextAnswer) && (isAnswerChanged || !string.IsNullOrWhiteSpace(oldTextSource))) { feedback.ValidateLength(textSourceBox, "Text Source", 1, 255, out success); } if (!string.IsNullOrWhiteSpace(newYouTubeUrl)) { if (!youTubeIsFromCandidate) { feedback.ValidateRequired(youTubeSourceBox, "YouTube Source", out success); } } if (feedback.ValidationErrorCount == 0) { string videoDescription = null; var videoRunningTime = default(TimeSpan); if (youTubeInfo != null) { videoDescription = youTubeInfo.ShortDescription; videoRunningTime = youTubeInfo.Duration; youTubeDescriptionBox.Text = videoDescription; youTubeRunningTimeBox.Text = videoRunningTime.FormatRunningTime(); } if (youTubeSourceBox != null) { youTubeSourceBox.Text = newYouTubeSource; } if (youTubeSourceUrlBox != null) { youTubeSourceUrlBox.Text = newYouTubeSourceUrl; } if (youTubeDateBox != null) { youTubeDateBox.Text = newYouTubeDate.DbDateToShortDate(); } if (youTubeFromCandidate != null) { youTubeFromCandidate.Checked = youTubeIsFromCandidate; } if (youTubeFromVoteUsa != null) { youTubeFromVoteUsa.Checked = !youTubeIsFromCandidate; } hasValue.Value = string.IsNullOrWhiteSpace(newTextAnswer) && string.IsNullOrWhiteSpace(newYouTubeUrl) ? string.Empty : "Y"; page.LogPoliticianAnswerChange(questionKey, sequence, oldTextAnswer, newTextAnswer, newTextSource); page.UpdatePoliticianAnswer(questionKey, sequence, question.IssueKey, newTextAnswer, newTextSource, newTextDate, newYouTubeUrl, videoDescription, videoRunningTime, newYouTubeSource, newYouTubeSourceUrl, newYouTubeDate); UpdateQuestion(questionKey, sequence); feedback.AddInfo("Your " + description + " entry was updated."); updateStatus = SecurePage.UpdateStatus.Success; updateCount++; } updatePanel.Update(); } } if (updateStatus != SecurePage.UpdateStatus.Failure) { if (newTextAnswer != textAnswerBox.Text) { updatePanel.Update(); } textAnswerBox.SetValue(newTextAnswer); if (!textIsFromCandidate) { if (string.IsNullOrWhiteSpace(newTextAnswer)) { newTextSource = string.Empty; newTextDate = VotePage.DefaultDbDate; } var newDateText = newTextDate.DbDateToShortDate(); Debug.Assert(textSourceBox != null, "sourceBox != null"); Debug.Assert(textDateBox != null, "dateBox != null"); if (newTextSource != textSourceBox.Text || newDateText != textDateBox.Text) { updatePanel.Update(); } textSourceBox.SetValue(newTextSource); textDateBox.SetValue(newDateText); } if (!youTubeIsFromCandidate) { var newYouTubeDateText = newYouTubeDate == VotePage.DefaultDbDate ? string.Empty : newYouTubeDate.DbDateToShortDate(); if (newYouTubeDateText != youTubeDateBox.Text) { updatePanel.Update(); } youTubeDateBox.SetValue(newYouTubeDateText); } } textAnswerBox.RemoveCssClass("badupdate"); } catch (Exception ex) { if (description == string.Empty) { description = "your response"; } feedback.AddError("There was an unexpected error updating " + description); feedback.HandleException(ex); updatePanel.Update(); } return(updateStatus); }