コード例 #1
0
        private async void MouseClickOnDatagrid(object sender, MouseButtonEventArgs e)
        {
            HttpClient client = new HttpClient();
            string     id     = partnersList[MyGridParters.SelectedIndex].GuID.ToString();
            string     url    = string.Format(@"http://localhost:56217/api/contacts?id={0}", Uri.EscapeDataString(id));

            await client.GetAsync(url)
            .ContinueWith(response =>
            {
                if (response.Exception != null)
                {
                    MessageBox.Show(response.Exception.Message);
                }
                else
                {
                    HttpResponseMessage message = response.Result;
                    string responseText         = message.Content.ReadAsStringAsync().Result;

                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    MyContact person         = jss.Deserialize <MyContact>(responseText);

                    string mailingLists = "";
                    foreach (var item in person.EmailLists)
                    {
                        mailingLists += item.Value + ", ";
                    }

                    Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                           (Action)(() =>
                    {
                        PartnerInfo.Text = $"Partner name - { person.FullName}\nCompany - {person.CompanyName}\nMailing Lists is {mailingLists} ";
                    }));
                }
            });
        }
コード例 #2
0
        private void UpdateSelectedbutton_Click(object sender, RoutedEventArgs e)
        {
            if (MyGridParters.SelectedItems.Count != 1)
            {
                return;
            }
            HttpClient client = new HttpClient();

            MyContact p = new MyContact();

            p.GuID         = partnersList[MyGridParters.SelectedIndex].GuID;
            p.EmailLists   = partnersList[MyGridParters.SelectedIndex].EmailLists;
            p.FullName     = PartnerNameTextbox.Text;
            p.CompanyName  = CompanyNameTextbox.Text;
            p.Country      = CountryNameTextbox.Text;
            p.Position     = PositionTextbox.Text;
            p.Email        = EmailTextbox.Text;
            p.DateInserted = partnersList[MyGridParters.SelectedIndex].DateInserted;


            HttpResponseMessage response = client.PutAsync(@"http://localhost:56217/api/contacts", p, new JsonMediaTypeFormatter()).Result;
            string message           = response.Content.ReadAsStringAsync().Result;
            JavaScriptSerializer jss = new JavaScriptSerializer();

            MessageBox.Show(message);
        }
コード例 #3
0
        private void Createbt_Click(object sender, RoutedEventArgs e)
        {
            HttpClient client = new HttpClient();

            MyContact p = new MyContact();

            p.FullName    = PartnerNameTextbox.Text;
            p.CompanyName = CompanyNameTextbox.Text;
            p.Country     = CountryNameTextbox.Text;
            p.Position    = PositionTextbox.Text;
            p.Email       = EmailTextbox.Text;

            HttpResponseMessage response = client.PostAsync(@"http://localhost:56217/api/contacts", p, new JsonMediaTypeFormatter()).Result;
            string message = response.Content.ReadAsStringAsync().Result;
        }