コード例 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost/apihost/");
            EmployeeResultModel employee = new EmployeeResultModel()
            {
                Name   = txtName.Text,
                Age    = int.Parse(txtAge.Text),
                Salary = int.Parse(txtSal.Text),
                DeptID = int.Parse(txtDeptId.Text)
            };

            var result = client.PostAsJsonAsync("api/employee", employee).Result;

            if (result.IsSuccessStatusCode)
            {
                FillEmployeesDataToGridView();
                label1.Text = "Added Successfully";
            }
            else
            {
                label1.Text = "Entry Error ";
            }
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost/apihost/");
            EmployeeResultModel employee = new EmployeeResultModel()
            {
                Name   = txtName.Text,
                Age    = int.Parse(txtAge.Text),
                Salary = int.Parse(txtSal.Text),
                DeptID = int.Parse(txtDeptId.Text)
            };

            var result = client.PostAsJsonAsync("api/employee", employee).Result;

            if (result.IsSuccessStatusCode)
            {
                label1.Text = "Added Successfully";
                var res = client.GetAsync("api/employee").Result;
                var msg = result.Content.ReadAsAsync <List <EmployeeResultModel> >().Result;
                dataGridView1.DataSource = msg;
            }
            else
            {
                label1.Text = "Entry Error ";
            }
        }