Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var updateInfo = new CpuUpdateInfo();

            updateInfo.Name        = txtName.Text;
            updateInfo.Description = txtDescription.Text;
            updateInfo.IpAddress   = txtIpAddress.Text;

            var info = Task.Run(async() => await _restClient.AddOrUpdateCpuClientInfo(updateInfo)).Result;

            if (info)
            {
                OnCpuAdded();
            }

            this.Close();
        }
        public async Task <bool> AddOrUpdateCpuClientInfo(CpuUpdateInfo cpuUpdateInfo)
        {
            var url = "http://localhost:9002/api/Cpu/Add";

            try
            {
                var json     = JsonConvert.SerializeObject(cpuUpdateInfo);
                var postData = new StringContent(json, Encoding.UTF8, "application/json");

                var response = await Client.PostAsync(url, postData);

                return(response.IsSuccessStatusCode);
            }
            catch (Exception)
            {
            }

            return(false);
        }