public async Task <bool> SendInformation(CustomerDetail customerDetail, int id) { if (customerDetail == null || !CrossConnectivity.Current.IsConnected) { return(false); } var serializedItem = JsonConvert.SerializeObject(customerDetail); var response = await client.PostAsync($"api/get-discount/{id}", new StringContent(serializedItem, Encoding.UTF8, "application/json")); return(response.IsSuccessStatusCode); }
async void OnSubmit(object sender, EventArgs e) { if (string.IsNullOrEmpty(entryPhone.Text)) { await DisplayAlert("Warning", "Please enter Phone Number", "Ok"); } else if (string.IsNullOrEmpty(entryName.Text)) { await DisplayAlert("Warning", "Please enter Name", "Ok"); } else if (string.IsNullOrEmpty(entryEmail.Text)) { await DisplayAlert("Warning", "Please enter Email", "Ok"); } else if (entryPhone.Text.Length < 10) { await DisplayAlert("Warning", "Phone Number should be of at least 10 digits.", "Ok"); } else { MailAddress addr = null; try { addr = new MailAddress(entryEmail.Text); if (addr.Address != entryEmail.Text) { await DisplayAlert("Warning", "Email ID is not valid.", "Ok"); } else { bool response = await DisplayAlert("Confirmation", "Do you want to submit?", "Yes", "No"); if (response) { CustomerDetail customerDetail = new CustomerDetail(); customerDetail.Phone = entryPhone.Text; customerDetail.Name = entryName.Text; customerDetail.Email = entryEmail.Text; bool result = await DependencyService.Get <CloudDataStore>().SendInformation(customerDetail, advertiseId); if (result) { await Navigation.PopToRootAsync(); } else { await DisplayAlert("Warning", "Please try again!", "Ok"); } } } } catch (Exception ex) { if (ex.GetType().ToString().Equals("System.FormatException")) { await DisplayAlert("Warning", "Email ID is not valid.", "Ok"); } } } }