Client Rest + WPF - PUT method (UPDATE)

Asked

Viewed 41 times

2

Hello, folks! I am trying to implement a method to update (update) information in a WPF application. Apparently, everything is correct, however, the method does not work. Here is the code:

This is the PUT on the server side (Controller):

public void Put(int id, [FromBody] string value)
        {
            Models.lok x = JsonConvert.DeserializeObject
                <Models.lok>(value);
            Models.PatDataContext dc = new Models.PatDataContext();
            Models.lok rsk = (from r in dc.Registras
                                           where r.id == id
                                           select r).Single();
            rsk.nome = x.nome;
            rsk.observacao = x.observacao;
            dc.SubmitChanges();
        }

And this is what’s in the customer:

private async void btnAlterar_Click(object sender, RoutedEventArgs e)
        {
            HttpClient httpClient = new HttpClient();
            httpClient.BaseAddress = new Uri(http://localhost:60417/);

            Modelo.Jos sa = new Modelo.Jos
            {
                Id = int.Parse(textBoxID.Text),
                Nome = textBoxNome.Text,
                Observacao = textBoxObs.Text
            };

            string seria = "=" + JsonConvert.SerializeObject(sa);
            var content = new StringContent(seria, Encoding.UTF8, "application/x-www-form-urlencoded");
            await httpClient.PutAsync("/api/Jos" + sa.Id, content);
        }

Thank you very much!

  • 1

    Do not post code link, post code itself.

  • All right. Thank you!

  • which method does not work?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.