コード例 #1
0
        private async void btnGüncelle_Click(object sender, EventArgs e)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:64124/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));

                    foreach (var item in KuList.ToList())
                    {
                        if (item.KullaniciID == int.Parse(txtCalisanSil.Text))
                        {
                            Kullanici kullanici = new Kullanici()
                            {
                                KullaniciID = item.KullaniciID,
                                Ad          = txtCalisanAd.Text,
                                Soyad       = txtCalisanSoyad.Text,
                                Adres       = txtAdres.Text,
                                Telefon     = txtTelefon.Text,
                                Email       = txtEmail.Text,
                                Sifre       = txtSifre.Text,
                                Rol         = txtRol.Text
                            };
                        }
                    }
                    var serializedProduct = JsonConvert.SerializeObject(kullanici);

                    var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");

                    var result = await client.PutAsync("api/Kullanici/" + txtCalisanSil.Text, content);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error happened: " + ex.Message);
            }
            Listele();
        }
コード例 #2
0
        private async void btnGetir_Click(object sender, EventArgs e)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:64124/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    using (var result = await client.GetAsync("api/Kullanici"))
                    {
                        if (result.IsSuccessStatusCode)
                        {
                            var value = result.Content.ReadAsStringAsync().Result;


                            KuList = JsonConvert.DeserializeObject <ResponseContent <Kullanici> >(value).Data.ToList();
                            foreach (var item in KuList.ToList())
                            {
                                if (item.KullaniciID == int.Parse(txtCalisanSil.Text))
                                {
                                    txtCalisanAd.Text    = item.Ad;
                                    txtCalisanSoyad.Text = item.Soyad;
                                    txtAdres.Text        = item.Adres;
                                    txtTelefon.Text      = item.Telefon;
                                    txtEmail.Text        = item.Email;
                                    txtSifre.Text        = item.Sifre;
                                    txtRol.Text          = item.Rol;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error happened: " + ex.Message);
            }
        }