private void ContactItemEventHandler(object sender, EventArgs e) { ContactItemSelectedArgs item = e as ContactItemSelectedArgs; ConversationWithOther conver = new ConversationWithOther(); conver.Name = "Noname conversation"; conver.UserIds = new long[] { item.userId }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.getUrl()); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token); HttpResponseMessage response = client.PostAsJsonAsync("/api/Conversations/WithMembers", conver).Result; if (response.StatusCode == System.Net.HttpStatusCode.Conflict || response.StatusCode == System.Net.HttpStatusCode.OK)//trùng hoặc vừa tạo mới { Conversation conversation = response.Content.ReadAsAsync <Conversation>().Result; RightPanel.Children.Clear(); ChattingPanel chattingPanel = new ChattingPanel(conversation.Id); RightPanel.Children.Add(chattingPanel); } else { } } }
private async void AddConversationWithOtherUser() { ContactListItem item = lvContact.SelectedItem as ContactListItem; long id = item.FromUserId; if (id == AppInstance.getInstance().GetUser().Id) { id = item.ToUserId; } string name = "Conversation with " + AppInstance.getInstance().GetFullname(id); if (!conversationnametb.Text.Equals("")) { name = conversationnametb.Text; } ConversationWithOther conver = new ConversationWithOther(); conver.Name = name; conver.UserIds = new long[] { id }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.getUrl()); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token); HttpResponseMessage response = client.PostAsJsonAsync("/api/Conversations/WithMembers", conver).Result; if (response.IsSuccessStatusCode) { this.DialogResult = true; } else { _404Mess mess = await response.Content.ReadAsAsync <_404Mess>(); errlb.Text = mess.Message; } } }