public async void ButtonSendChatMessage(string sMessageText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sMessageText))
                {
                    var chatModel = new ChatMessageViewModel
                    {
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        ContactId   = contactId,
                        Message     = sMessageText.Trim(' ', '\n'),
                        IsRead      = false,
                        IsRecieved  = false,
                        IsSend      = false,
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };


                    var chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                    if (chatConversationResponse.success)
                    {
                        if (chatConversationResponse.chatConversation != null)
                        {
                            var message = ChatMessageRepository.SaveChatMessage(chatModel, chatConversationResponse.chatConversation.ChatId);
                            chatModel.MobiledatabaseId = message.id;
                            chatModel.ChatId           = chatConversationResponse.chatConversation.ChatId;
                            chatModel.IsRead           = false;
                            chatModel.IsRecieved       = false;
                            chatModel.IsSend           = false;
                            var msg = new Message
                            {
                                Type = MessageType.Outgoing,
                                Text = sMessageText.Trim()
                            };

                            messages.Add(msg);
                            tableView.InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(messages.Count - 1, 0) }, UITableViewRowAnimation.None);
                            ScrollToBottom(true);
                        }
                    }
                    lstAttachments = new List <AttachmentViewModel>();
                    try
                    {
                        var result = await new ChatService().PostChat(chatModel);

                        if (result.Status == 2 || result.Status == 1)
                        {
                            var ChatResponse = JsonConvert.DeserializeObject <PostChatResponseViewModel>(result.Response.ToString());

                            if (chatConversationResponse.chatConversation == null)
                            {
                                ChatConversationRepository.SaveConverstionNewFromServer(ChatResponse.Chat);
                                chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                                if (chatConversationResponse.success)
                                {
                                    ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                    var savedMessages = ChatMessageRepository.SaveChatMessage(ChatResponse.ChatMessage, chatConversationResponse.chatConversation.ChatId);
                                }
                                LoadLocalLatestMessages();
                                Console.WriteLine("CHAT POSTED : " + result);
                            }
                            else
                            {
                                chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                                if (chatConversationResponse.success)
                                {
                                    ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, ChatResponse.ChatMessage.Message, "");
                                }
                                var savedMessages = ChatMessageRepository.updateChatMessage(ChatResponse.ChatMessage);
                                LoadLocalLatestMessages();
                                await _objChatSignalRService.Send(chatConversationResponse.chatConversation.ContactId.ToString(), ChatResponse.ChatMessage);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
        public async void ButtonSendChatMessage()
        {
            try
            {
                if (!string.IsNullOrEmpty(txtChatSendMessage.Text) || lstAttachments.Count > 0)
                {
                    txtChatSendMessage.Text = txtChatSendMessage.Text.Trim(' ', '\n');

                    var chatModel = new ChatMessageViewModel
                    {
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        ContactId   = contactId,
                        Message     = txtChatSendMessage.Text,
                        IsRead      = false,
                        IsRecieved  = false,
                        IsSend      = false,
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };


                    chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);
                    if (chatConversation != null)
                    {
                        var message = ChatMessageRepository.SaveChatMessage(chatModel, chatConversation.ChatId);
                        chatModel.MobiledatabaseId = message.id;
                        chatModel.ChatId           = chatConversation.ChatId;
                        chatModel.IsRead           = false;
                        chatModel.IsRecieved       = false;
                        chatModel.IsSend           = false;
                        mAdapter.add(message);
                        mAdapter.NotifyDataSetChanged();
                        mRecyclerView.ScrollToPosition(mAdapter.ItemCount - 1);
                        txtChatSendMessage.Text = "";
                    }
                    lstAttachments          = new List <AttachmentViewModel>();
                    txtChatSendMessage.Text = "";
                    try
                    {
                        var result = await new ChatService().PostChat(chatModel);

                        if (result.Status == 2 || result.Status == 1)
                        {
                            var ChatResponse = JsonConvert.DeserializeObject <PostChatResponseViewModel>(result.Response.ToString());

                            if (chatConversation == null)
                            {
                                ChatConversationRepository.SaveConverstionNewFromServer(ChatResponse.Chat);
                                chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);

                                ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                var savedMessages = ChatMessageRepository.SaveChatMessage(ChatResponse.ChatMessage, chatConversation.ChatId);

                                LoadLocalLatestMessages();
                                txtChatSendMessage.Text = "";
                                Console.WriteLine("CHAT POSTED : " + result);
                            }
                            else
                            {
                                chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);

                                ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                var savedMessages = ChatMessageRepository.updateChatMessage(ChatResponse.ChatMessage);
                                LoadLocalLatestMessages();
                                await _objChatSignalRService.Send(chatConversation.ContactId.ToString(), ChatResponse.ChatMessage);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }