コード例 #1
0
        void SurveysAdapter.OnSendClickListener.OnResponseSendClicked(int position, int checkedId, string reply)
        {
            Console.Write("in clicked" + position);
            var    data      = mData[position];
            string replyText = "";

            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + prefs.GetString(CONSTANTS.AUTH_HEADER, ""));
            switch (data.QuestionType)
            {
            case QuestionType.Choice:
            {
                if (checkedId == Resource.Id.radioButtonYes)
                {
                    replyText = "Yes";
                }
                else
                {
                    replyText = "No";
                }

                break;
            }

            case QuestionType.TextEntry:
            {
                replyText = reply;
                break;
            }
            }
            var responseToSend = new SurveyResponse
            {
                UserId                     = prefs.GetString(CONSTANTS.USERID, ""),
                SurveyId                   = data.SurveyId,
                StudyGroupId               = data.StudyGroupId,
                UserResponseText           = replyText,
                SurveyResponseReceivedTime = DateTime.Now.ToString(CONSTANTS.DATE_FORMAT)
            };

            client.PostAsync(CONSTANTS.POST_RESPONSE_URL, new FormUrlEncodedContent(responseToSend.ToDict()))
            .ContinueWith((response) =>
            {
                Console.Write(response.Status);
                if (response.IsCompleted)
                {
                    GetMessagesAsync();
                }
                else
                {
                    Console.Write(response.Result);
                }
            });
        }