private void Acceptbt_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; ContactListItem contact = button.DataContext as ContactListItem; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url); 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.PutAsJsonAsync("/api/Contacts/" + contact.FromUserId, new Contact() { Status = 1 }).Result; if (response.IsSuccessStatusCode) { try { Bgworker.RunWorkerAsync(100); } catch (Exception ex) { } } else { _404Mess err = response.Content.ReadAsAsync <_404Mess>().Result; System.Windows.MessageBox.Show(err.Message); } } }
private void ToggleButton_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; ConversationMemberItem user = button.DataContext as ConversationMemberItem; ConfirmDialog dialog = new ConfirmDialog("Approve user " + user.FullName + " become host of coversation"); bool?result = dialog.ShowDialog(); if (result == true) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token); ConversationMember memberinconversation = new ConversationMember() { UserIds = user.Id }; HttpResponseMessage response = client.PutAsJsonAsync("/api/Conversations/HostMember/" + ConversationId, memberinconversation).Result; if (response.IsSuccessStatusCode) { LoadUserList(); } else { _404Mess err = response.Content.ReadAsAsync <_404Mess>().Result; System.Windows.MessageBox.Show(err.Message); } } } }
private void btOk_Click(object sender, RoutedEventArgs e) { foreach (var item in lvContact.SelectedItems) { ContactListItem contact = item as ContactListItem; long userid = contact.ToUserId; if (contact.ToUserId == AppInstance.getInstance().GetUser().Id) { userid = contact.FromUserId; } MemberConversation mem_conver = new MemberConversation() { ConversationId = ConversationId, UserId = userid }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url); 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/Members", mem_conver).Result; if (response.IsSuccessStatusCode) { this.DialogResult = true; } else { _404Mess mess = response.Content.ReadAsAsync <_404Mess>().Result; errlb.Text = mess.Message; } } } }
private void btnSignUp_Click(object sender, RoutedEventArgs e) { string password = PasswordBox.Password; string repassword = RePasswordBox.Password; if (password.Equals(repassword)) { string user = usernameBox.Text.Trim(); if (!user.Equals("")) { //chưa authorized string fullname = fullnameBox.Text; UserSignup signup = new UserSignup() { FullName = fullname, Password = password, Username = user, Avatar = 0 }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultis.Ultils.url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("/api/Users/Register", signup).Result; if (response.IsSuccessStatusCode) { LoginWindown windown = new LoginWindown(); windown.SetAccount(user, password); windown.Show(); this.Close(); } else { _404Mess mess = response.Content.ReadAsAsync <_404Mess>().Result; ErrLable.Content = mess.Message; } } } else { ErrLable.Content = "Username not empty"; } } else { ErrLable.Content = "Password is not match"; } }
private void deleteuser_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; ConversationMemberItem user = button.DataContext as ConversationMemberItem; string content = "Kick user " + user.FullName; if (user.Id == AppInstance.getInstance().GetUser().Id) { content = "Out this conversation "; } ConfirmDialog dialog = new ConfirmDialog(content); bool? result = dialog.ShowDialog(); if (result == true) { if (user.Id == ConversationHost) { System.Windows.MessageBox.Show("Host cannot out the conversation"); return; } using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url + "/api/Conversations/Members"); 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.DeleteAsync("/api/Conversations/Members/" + ConversationId + "/" + user.Id).Result; if (response.IsSuccessStatusCode) { } else { _404Mess mess = response.Content.ReadAsAsync <_404Mess>().Result; System.Windows.MessageBox.Show(mess.Message); } } } }
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; } } }
private void btUpdateAvatar_Click(object sender, RoutedEventArgs e) { string path = ImageSupportInstance.getInstance().OpenChooseImageDialogBox(); if (!path.Equals("")) { Resource res = ImageSupportInstance.getInstance().UploadImage(path, 360, 360); User currentuser = AppInstance.getInstance().GetUser(); currentuser.Avatar = res.Id; AppInstance.getInstance().SetUser(currentuser); UserSignup user = new UserSignup() { Avatar = currentuser.Avatar, FullName = currentuser.FullName, Password = null, Username = null }; using (HttpClient client = new HttpClient()) { string url = Ultils.getUrl(); client.BaseAddress = new Uri(url); 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.PutAsJsonAsync("/api/Users/Owner", user).Result; if (response.IsSuccessStatusCode) { UpdateIconEventhandler(this, new EventArgs()); } else { _404Mess mess = response.Content.ReadAsAsync <_404Mess>().Result; System.Windows.MessageBox.Show(mess.Message); } } } }
private async Task LoginAsync() { string username = usernameBox.Text; string pass = PasswordBox.Password; if (username.Split('-').Count() > 1) { Ultils.url = username.Split('-')[1]; username = username.Split('-')[0]; } LoginUser userLogin = new LoginUser() { Username = username, Password = pass }; string url = Ultils.getUrl(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("api/Users/Authenticate", userLogin).Result; if (response.IsSuccessStatusCode) { User user = await response.Content.ReadAsAsync <User>(); AppInstance.getInstance().SetUser(user); } else { _404Mess mess = await response.Content.ReadAsAsync <_404Mess>(); ErrLable.Content = mess.Message; } } }
private async void btOk_Click(object sender, RoutedEventArgs e) { string username = tbInput.Text; long ToUserId = 0; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token); HttpResponseMessage respone = client.GetAsync("/api/Users/ByUserName/" + username, HttpCompletionOption.ResponseContentRead).Result; if (respone.IsSuccessStatusCode) { User user = respone.Content.ReadAsAsync <User>().Result; ToUserId = user.Id; } else { _404Mess mess = respone.Content.ReadAsAsync <_404Mess>().Result; errlb.Text = mess.Message; } } if (ToUserId != 0 && AppInstance.getInstance().GetUser().Id != ToUserId) { Contact contact = new Contact() { ToUserId = ToUserId }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Ultils.url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppInstance.getInstance().GetUser().Token); HttpResponseMessage respone = client.PostAsJsonAsync("/api/Contacts/", contact).Result; if (respone.IsSuccessStatusCode) { this.DialogResult = true; //send to hub contact = new Contact() { ToUserId = ToUserId, FromUserId = AppInstance.getInstance().GetUser().Id, Status = 0 }; string json = JsonConvert.SerializeObject(contact); try { await connection.InvokeAsync("SendMessage", "contact", json); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } else { _404Mess mess = respone.Content.ReadAsAsync <_404Mess>().Result; errlb.Text = "Request have been sent or already exist"; } } } }