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);
            }
        }
Exemple #2
0
        private async void OnSend(object sender, EventArgs e)
        {
            try
            {
                if (!IsInValidInput())
                {
                    ShowProgress("Sending....");
                    Models.Message message = new Models.Message
                    {
                        SenderId    = CurrentUser.Id,
                        ReceiverId  = SelectedUserId,
                        MessageBody = etMessageBody.Text,
                        MessageTime = DateTime.Now.ToString("yyyy/MM/dd HH: mm:ss tt"),
                        IsRead      = false,
                        IsUnLocked  = false,
                        RegionId    = SelectedRegionId
                    };

                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Access_Token);

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

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