コード例 #1
0
        private async void OnSend(object sender, EventArgs e)
        {
            try
            {
                if (!IsInValidInput())
                {
                    Models.Message message = new Models.Message
                    {
                        SenderId    = CurrentUser.Id,
                        ReceiverId  = SelectedUser.Id,
                        MessageBody = etMessageBody.Text,
                        MessageTime = new DateTime().ToString(),
                        IsRead      = false
                    };
                    HttpClient client = new HttpClient();

                    StringContent content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8,
                                                              "application/json");


                    HttpResponseMessage result = await client.PostAsync(Constants.SEND_MESSAGE_URL, new FormUrlEncodedContent(message.ToMap()));

                    if (result.IsSuccessStatusCode)
                    {
                        Toast.MakeText(this, "Message sent!", ToastLength.Short).Show();
                        Intent GoBackToInbox = new Intent(this, typeof(InboxActivity));
                        StartActivity(GoBackToInbox);
                        Finish();
                    }
                    else
                    {
                        Log.Debug(Constants.TAG, "Error occured");
                    }
                }
            }catch (Exception exp)
            {
                Log.Debug(Constants.TAG, exp.Message);
            }
        }