public void CreateContact(ChatContact contact) { Debug.WriteLine($"AddContact({contact.ID}, {contact.Name}"); ContactsMap.Add(contact.ID, contact); DatabaseController.Insert(contact); SortContacts(); }
public List<ChatContact> GetContactList(string username) { DBConnection DBcon = DBConnection.Instance(); using (MySqlConnection con = DBcon.GetConnection()) { using (MySqlCommand cmd = con.CreateCommand()) { string mytable = "contacts_" + username; cmd.CommandText = string.Format( "SELECT * FROM {0}", mytable); cmd.Parameters.AddWithValue("@username", username); MySqlDataReader dataReader; try { dataReader = cmd.ExecuteReader(); Debug.WriteLine("--- MySql DAO > Contacts retrieved from the database"); } catch (Exception exception) { Debug.WriteLine("Error: " + exception.Message); Debug.WriteLine("Stack trace: \n\n" + exception.StackTrace); return null; } List<ChatContact> contactList = new List<ChatContact>(); while (dataReader.Read()) { ChatContact chatContact = new ChatContact(); chatContact.Contact = dataReader.GetString("contact"); contactList.Add(chatContact); } return contactList; } } }
private async void CreateContactFunction(object obj) { var contact = new ChatContact(Guid.Parse(ContactInputGuidText), ContactInputNameText); Controller.CreateContact(contact); await RootPage.NavigatePop(); }
private async void DeleteMethod(object obj) { try { if (await UserDialogs.Instance.ConfirmAsync(new ConfirmConfig { CancelText = "Cancel", OkText = "Ok", Message = App.Idioma.TwoLetterISOLanguageName == MyIdioma.Español ? "¿Estás seguro de eliminar el chat?" : "Are you sure you want to delete the chat ?", })) { var x = (ChatDetail)obj; ChatContact ch = new ChatContact() { UserID = x.UserID, ContactUserID = x.ContactID, IDPosition = x.IDPosition }; //Agregar el metodo de borrado de position if (await Services.Chat.ChatService.DeleteContactAsync(ch)) { //if (ItemIndex >= 0) var takeoffsSelected = ChatItems.Where(z => z.IDPosition == ch.IDPosition && z.UserID == ch.UserID && z.ContactID == ch.ContactUserID).FirstOrDefault(); ChatItems.Remove(takeoffsSelected); await Application.Current.MainPage.DisplayAlert("JobMe", App.Idioma.TwoLetterISOLanguageName == MyIdioma.Español? "Se elimino correctamente el chat" : "Chat successfully deleted", "OK"); //ListView.ResetSwipe(); //Activar la etiqueta de no tienes contactos IsVisible = ChatItems.Count > 0 ? false : true; //MessagingCenter.Send<EditJobViewModel, int>(this, "UpdateList", 1); } else { await Application.Current.MainPage.DisplayAlert("JobMe", App.Idioma.TwoLetterISOLanguageName == MyIdioma.Español? "Ocurrío un error al eliminar el chat" : "Error deleting chat", "OK"); } } //ListView.ResetSwipe(); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("JobMe", App.Idioma.TwoLetterISOLanguageName == MyIdioma.Español? "Ocurrío un error al eliminar el chat" : "Error deleting chat", "OK"); //throw; } }
public void SelectConversation(ChatContact contact) { ChatConversation conversation; if (!ConversationsMap.TryGetValue(contact.ID, out conversation)) { conversation = new ChatConversation(contact); ConversationsMap.Add(contact.ID, conversation); } SelectConversation(conversation); }
public static async Task <int> AddContactAsync(ChatContact ch) { var client = new HttpClient(); var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/AddContact"; //var uri = "https://localhost:44327/api/user"; // Request body // byte[] byteData = Encoding.UTF8.GetBytes("{}"); byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ch)); string msj = string.Empty; using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(uri, content); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); try { return(JsonConvert.DeserializeObject <int>(result)); } catch (Exception ex) { return(0); throw; } } else { return(0); msj = "Ocurrio un error al agregar la vacante"; } } }
public void AddMessage(ChatMessage msg) { var other = (Me == msg.RecipientID ? msg.SenderID : msg.RecipientID); ChatConversation conversation; if (!ConversationsMap.TryGetValue(other, out conversation)) { ChatContact contact; if (!ContactsMap.TryGetValue(other, out contact)) { contact = new ChatContact(other, "no name"); ContactsMap.Add(other, contact); } conversation = new ChatConversation(contact); ConversationsMap.Add(other, conversation); } conversation.Messages.Add(msg); }
public static async Task <bool> DeleteContactAsync(ChatContact ch) { var client = new HttpClient(); var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/DeleteContact"; byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ch)); string msj = string.Empty; using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(uri, content); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); try { return(JsonConvert.DeserializeObject <bool>(result)); } catch (Exception ex) { return(false); throw; } } else { return(false); } } }