protected void AnswerSubmitButton_OnClick(object sender, EventArgs e) { var logginedUser = HttpContext.Current.User.Identity; if (logginedUser.IsAuthenticated) // only logedin users can answer to question { int questionId; if (int.TryParse(Request.QueryString["QuestionID"], out questionId) && questionId > 0) { using (var control = new AnswerController()) { control.AnswerToQuestion(questionId, AnswerBodyTextBox.Text); } AnswerBodyTextBox.Text = ""; QuestionDetailFormView.DataBind(); AnswersList.DataBind(); } else { ErrorMessage.InnerText = "Please try again later"; ErrorDiv.Visible = true; } } else { var currentUrl = HttpUtility.UrlEncode(Request.Url.PathAndQuery); Response.Redirect($"~/Login.aspx?ReturnUrl={currentUrl}"); } }
protected void QuestionVote_OnClick(object sender, EventArgs e) { string username; var logginedUser = HttpContext.Current.User.Identity; var vote = (LinkButton)sender; var questionId = int.Parse(vote.CommandArgument); using (var control = new QuestionController()) { username = control.GetQuestionAutherEmail(questionId); } if (logginedUser.IsAuthenticated) // only logined users can vote { if (logginedUser.Name != username) // nobody can't voye himself/herself { using (var control = new QuestionController()) { control.ManageVote( vote.ID.ToLower().Contains("up") ? QuestionController.VoteType.Up : QuestionController.VoteType.Down, questionId); } } else { ErrorMessage.InnerText = "You can not vote yourself."; ErrorDiv.Visible = true; } QuestionDetailFormView.DataBind(); } else { var currentUrl = HttpUtility.UrlEncode(Request.Url.PathAndQuery); Response.Redirect($"~/Login.aspx?ReturnUrl={currentUrl}"); } }
protected void QuestionSubmitCommentButton_OnClick(object sender, EventArgs e) { var logginedUser = HttpContext.Current.User.Identity; if (logginedUser.IsAuthenticated) // only logined users can submit comment { var submitButton = (Button)sender; var questionId = int.Parse(submitButton.CommandArgument); var commentTextBox = (TextBox)QuestionDetailFormView.FindControl("QuestionCommentBody"); using (var control = new QuestionController()) { control.AddComment(questionId, commentTextBox.Text); } QuestionDetailFormView.DataBind(); } else { var currentUrl = HttpUtility.UrlEncode(Request.Url.PathAndQuery); Response.Redirect($"~/Login.aspx?ReturnUrl={currentUrl}"); } }