Exemple #1
0
        public async Task <HttpResponseMessage> SendCustomerToServer(RequestItem request)
        {
            // customers/:phone/:name/:addressold/:typeofcar/:timereq/:statusforreq
            var myContent   = JsonConvert.SerializeObject(request);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await HTTP_CLIENT.PostAsync("dienthoaivien/customers", byteContent);

            return(response);
        }
Exemple #2
0
        private async void btnGui_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSoDienThoai.Text) && !string.IsNullOrEmpty(txtHoTen.Text) && !string.IsNullOrEmpty(txtViTri.Text))
            {
                try
                {
                    //Console.WriteLine("3");
                    if (cbbLoaiXe.SelectedIndex > -1)
                    {
                        RequestItem request = new RequestItem();
                        request.addressold   = txtViTri.Text;
                        request.phone        = txtSoDienThoai.Text;
                        request.statusforreq = 1;
                        request.typeofcar    = ((TypeCar)cbbLoaiXe.SelectedItem).Id;
                        request.timereq      = DateTime.Now.Ticks;
                        request.name         = txtHoTen.Text;

                        HttpResponseMessage result = await SendCustomerToServer(request);

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            string str = await result.Content.ReadAsStringAsync();

                            MessageBox.Show("Gửi thành công");
                        }
                        else
                        {
                            MessageBox.Show("Gửi thất bại");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }