Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        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);
                    }
                }
            }
        }