コード例 #1
0
        private void btnResponse_Click(object sender, RoutedEventArgs e)
        {
            Response response     = new Response();
            string   responseText = txtResponse.Text;

            if (responseText.Length > 0)
            {
                try
                {
                    Question question = (Question)gridQuestions.SelectedItem;

                    response.Date         = DateTime.Now;
                    response.QuestionID   = question.QuestionID;
                    response.UserID       = _accessToken.UserID;
                    response.UserResponse = responseText;
                    string message = "";
                    message = "Your question '" + question.Title + "' has received a new response from Expert " + _accessToken.UserName + ".";

                    if (article.BlogID != 0)
                    {
                        response.BlogID = article.BlogID;
                    }
                    else
                    {
                        response.BlogID = null;
                    }

                    if (responseText.Length <= 250)
                    {
                        responseManager.AddResponse(response);
                        messageManager.SendMessage(message, "Your question has a new response", _accessToken.UserName, userManager.GetUser(question.CreatedBy).UserName);
                        //if (response.BlogID == null)
                        //    messageManager.SendMessage(message, "Your question has a new response", _accessToken.UserName, userManager.GetUser(question.CreatedBy).UserName);
                        btnResponse.Content = "Edit";
                        this.NavigationService.Navigate(new ExpertPages.SearchForQuestions(_accessToken, question));
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Response oldResponse = responseManager.GetResponseByQuestionIDAndUser(response.QuestionID, _accessToken.UserID);
                        responseManager.EditResponse(response, oldResponse);
                        Question question = (Question)gridQuestions.SelectedItem;
                        this.NavigationService.Navigate(new ExpertPages.SearchForQuestions(_accessToken, question));
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Your response could not get through.");
                    }
                }
            }
            else
            {
                lblReply.Content    = "Enter a response";
                lblReply.Foreground = System.Windows.Media.Brushes.Red;
            }
        }