public async void AddMessagetoFirebase() { try { if (Common.CheckConnection()) { var item = new ChatDetailListModel() { sender_user_id = user_id, job_id = JobData.job_id, coordinator_id = JobData.coordinator_id, worker_id = JobData.worker_id, customer_id = null, sender_user_Name = user_name, coordinator_Name = !string.IsNullOrEmpty(JobData.coordinator_Name) ? AppResource.coordinator_Name : JobData.coordinator_Name, job_Name = ChatDetailTitle, receiver_user_Name = null, worker_Name = JobData.worker_Name, customer_Name = null, image_url = null, file_url = null, is_file = false, is_image = false, is_loading = false, IsViewBtnVisible = false, is_message = true, msg_datetime = DateTime.Now, user_message = MessageEntry, user_message_time = DateTime.Now.ToString("dd/MM/yyyy, hh:mm:ss tt"), is_sender = true, time_stamp = DependencyService.Get <IGetTimeStamp>().TimeStamp() }; //var request = new ChatDetailModelApi() //{ // from_user_id = user_id, // to_user_id = JobData.job_id //}; Chatdetailresponse response; try { MessageEntry = string.Empty; response = await _webApiRestClient.GetAsync <Chatdetailresponse>(string.Format(ApiUrl.AddGroupChatRequest, JobData.job_id, Convert.ToInt32(Enums.UserTypeEnum.Customer))); } catch (Exception ex) { Console.WriteLine("SendMsgApi_Exception:- " + ex.Message); response = null; await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_ServerError, msDuration : 3000); return; } if (response != null) { if (response.status) { try { AllChatDetailList.Add(item); } catch (Exception ex) { } ChatDetailList = AllChatDetailList; MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else if (response.message == null) { try { AllChatDetailList.Add(item); } catch (Exception ex) { } ChatDetailList = AllChatDetailList; MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else { await MaterialDialog.Instance.SnackbarAsync(message : response.message, msDuration : 3000); } var msgItem = new GroupChatDBModel() { GroupJobId = JobData.job_id, UserMessagesList = ChatDetailList }; if (groupChatMessagesDbService.IsGroupChatPresentInDB()) { var newmsgItem = groupChatMessagesDbService.ReadAllItems().Where(x => x.GroupJobId == JobData.job_id).ToList(); if (newmsgItem != null && newmsgItem.Count > 0) { var msgID = newmsgItem.FirstOrDefault().ID; msgItem.ID = msgID; BsonValue bsonid = msgID; groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem); } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } } else { await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_InternetError, msDuration : 3000); } } catch (Exception ex) { //await MaterialDialog.Instance.SnackbarAsync(message: ex.Message, // msDuration: 3000); Console.WriteLine("SendMsgCommand_Exception:- " + ex.Message); } }
public async void AddMessageFirebase(ChatDetailListModel item) { try { if (Common.CheckConnection()) { Chatdetailresponse response; try { response = await _webApiRestClient.GetAsync <Chatdetailresponse>(string.Format(ApiUrl.AddGroupChatRequest, JobData.job_id, Convert.ToInt32(Enums.UserTypeEnum.Customer))); } catch (Exception ex) { Console.WriteLine("SendMsgApi_Exception:- " + ex.Message); response = null; IsBackPress = true; await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_ServerError, msDuration : 3000); return; } if (response != null) { if (response.status) { MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else if (response.message == null) { MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else { await MaterialDialog.Instance.SnackbarAsync(message : response.message, msDuration : 3000); } var msgItem = new GroupChatDBModel() { GroupJobId = JobData.job_id, UserMessagesList = ChatDetailList }; if (groupChatMessagesDbService.IsGroupChatPresentInDB()) { var newmsgItem = groupChatMessagesDbService.ReadAllItems().Where(x => x.GroupJobId == JobData.job_id).ToList(); if (newmsgItem != null && newmsgItem.Count > 0) { var msgID = newmsgItem.FirstOrDefault().ID; msgItem.ID = msgID; BsonValue bsonid = msgID; groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem); } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } IsBackPress = true; } else { await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_InternetError, msDuration : 3000); } } catch (Exception ex) { //await MaterialDialog.Instance.SnackbarAsync(message: ex.Message, // msDuration: 3000); IsBackPress = true; Console.WriteLine("SendMsgCommand_Exception:- " + ex.Message); } }