Ejemplo n.º 1
0
        private void upButton_Click(object sender, EventArgs e)
        {
            BooksTable books = new BooksTable()
            {
                ID      = int.Parse(idText.Text),
                TITLE   = titleText.Text.ToString(),
                VERSION = verText.Text.ToString(),
                AUTHOR  = authText.Text.ToString(),
                GENRE   = genText.Text.ToString(),
                YEAR    = int.Parse(yearText.Text)
            };

            UpdateBook(books, idText.Text);
            GetBooks();
        }
Ejemplo n.º 2
0
 private void UpdateBook(BooksTable books, string id)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("https://webapibooks.azurewebsites.net/");
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         try
         {
             HttpResponseMessage response = client.PutAsJsonAsync($"api/Books/" + id, books).Result;
             //response.Content.ReadAsStringAsync();
             response.EnsureSuccessStatusCode();
             books = response.Content.ReadAsAsync <BooksTable>().Result;
             messageLab.ForeColor = Color.Green;
             messageLab.Text      = "Książka została zaaktualizowana";
         }
         catch (Exception e)
         {
             messageLab.ForeColor = Color.Green;
             messageLab.Text      = e.Message;
         }
     }
 }
Ejemplo n.º 3
0
 private void AddBook(BooksTable books)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("https://webapibooks.azurewebsites.net/");
         var response = client.PostAsJsonAsync("api/Books", books).Result;
         if (response.IsSuccessStatusCode)
         {
             idText.Clear();
             titleText.Clear();
             verText.Clear();
             authText.Clear();
             genText.Clear();
             yearText.Clear();
             messageLab.ForeColor = Color.Green;
             messageLab.Text      = "Książka została dodana do bazy";
         }
         else
         {
             messageLab.ForeColor = Color.Red;
             messageLab.Text      = "Wystąpił błąd !";
         }
     }
 }