Пример #1
0
        private async void EditCustomer()
        {
            try
            {
                string EditUrl = baseUrl + "api/Customer/Edit";
                tblCustomer objCust = new tblCustomer();

                objCust.FirstName = Convert.ToString(FirstNameTxt.Text);
                objCust.LastName = txtLastName.Text.ToString();
                objCust.Email = txtEmail.Text.ToString();
                objCust.PhoneNumber = txtPhoneNumber.Text.ToString();
                objCust.Status = txtStatus.Text.ToString();

                if ((objCust != null) && (objCust.Email != ""))
                {
                    using (var objClient = new HttpClient())
                    {
                        string contentType = "application/json";
                        var serializedCustomer = JsonConvert.SerializeObject(objCust);
                        var content = new StringContent(serializedCustomer, Encoding.UTF8, contentType);
                        var result = await objClient.PostAsync(EditUrl, content);
                        GetCustomer_(url);
                    }
                }
                else
                {
                    MessageBox.Show("Email Id is Must!");
                }
            }
            catch
            {
                MessageBox.Show("Invalid Customer!!");
            }
        }
Пример #2
0
        private async void CreateCustomer()
        {
            try
            {
                string InsertUrl = baseUrl + "api/Customer/Create";
                
                tblCustomer objCust = new tblCustomer();
                objCust.LastName = txtLastName.Text.ToString();
                objCust.Email = txtEmail.Text.ToString();
                objCust.PhoneNumber = txtPhoneNumber.Text.ToString();
                objCust.Status = txtStatus.Text.ToString();

                if ((objCust != null) && (objCust.Email != ""))
                {
                    using (var objClient = new System.Net.Http.HttpClient())
                    {
                        objClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        string contentType = "application/json";
                        objClient.BaseAddress = new Uri(InsertUrl);
                        var serializedCustomer = JsonConvert.SerializeObject(objCust);
                        var content = new StringContent(serializedCustomer, Encoding.UTF8, contentType);
                        var result = await objClient.PostAsync(InsertUrl, content);
                        GetCustomer_(url);
                        Clear();
                    }
                }
                else
                {
                    MessageBox.Show("Email Id is Must!");
                }
            }
            catch
            {
                MessageBox.Show("Invalid Customer!!");
            }
        }