private async void btnUpdateCar_ClickAsync(object sender, EventArgs e) { using (HttpClient client = new HttpClient()) //Fix { CarRequestDto UpdateCar = new CarRequestDto { CarBrand = txtBrand.Text, CarKM = int.Parse(txtCarKm.Text), AirBagCount = byte.Parse(txtAirbagCount.Text), CarModel = txtModel.Text, CarPhotoURL = txtPhotoUrl.Text, CarPriceForRent = decimal.Parse(txtRentPrice.Text), CarSeatCount = byte.Parse(txtSeatCount.Text), MinCustomerAge = byte.Parse(txtMinCustomerAge.Text), MinDrivingLicenseAge = byte.Parse(txtMinLicenceAge.Text), MaxKmPerDay = int.Parse(txtMaxKm.Text), CarTrunkVolume = short.Parse(txtTrunkVolume.Text) }; client.BaseAddress = new Uri("http://165.22.91.48/api/"); //Fix client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Fix var serializedUpdateCar = JsonConvert.SerializeObject(UpdateCar); var content = new StringContent(serializedUpdateCar, Encoding.UTF8, "application/json"); var response = await client.PostAsync("Car/UpdateCar?CarID=" + int.Parse(txtCarId.Text), content); if (response.IsSuccessStatusCode) { MessageBox.Show("Successfull"); } } }
private void BtnUpdateCar_Click(object sender, EventArgs e) { using (var CarService = new CarServiceSoapClient()) { CarRequestDto UpdatedCar = new CarRequestDto { CarBrand = txtBrand.Text, CarKM = int.Parse(txtCarKm.Text), AirBagCount = byte.Parse(txtAirbagCount.Text), CarModel = txtModel.Text, CarPhotoURL = txtPhotoUrl.Text, CarPriceForRent = decimal.Parse(txtRentPrice.Text), CarSeatCount = byte.Parse(txtSeatCount.Text), MinCustomerAge = byte.Parse(txtMinCustomerAge.Text), MinDrivingLicenseAge = byte.Parse(txtMinLicenceAge.Text), MaxKmPerDay = int.Parse(txtMaxKm.Text), CarTrunkVolume = short.Parse(txtTrunkVolume.Text) }; CarService.UpdateCar(UpdatedCar, int.Parse(txtCarId.Text)); CarService.Close(); } }