/// <summary> /// Event occurs when the Button control is clicked. /// Here we will call phone lookup API, parse result and populate result on UI /// </summary> /// <param name="sender">Object sender</param> /// <param name="e">event data.</param> protected void ButtonFindClick(object sender, EventArgs e) { try { errorBox.Visible = false; LiteralErrorMessage.Text = string.Empty; if (!string.IsNullOrEmpty(textBoxPhoneNumber.Text)) { int statusCode = -1; string description = string.Empty; string errorMessage = string.Empty; NameValueCollection nameValues = new NameValueCollection(); nameValues["phone"] = textBoxPhoneNumber.Text; nameValues["api_key"] = WhitePagesConstants.ApiKey; WhitePagesWebService webService = new WhitePagesWebService(); // Call method ExecuteWebRequest to execute backend API and return response stream. Stream responseStream = webService.ExecuteWebRequest(nameValues, ref statusCode, ref description, ref errorMessage); // Checking respnseStream null and status code. if (statusCode == 200 && responseStream != null) { // Reading response stream to StreamReader. StreamReader reader = new StreamReader(responseStream); // Convert stream reader to string JSON. string responseInJson = reader.ReadToEnd(); // Dispose response stream responseStream.Dispose(); // Calling ParsePhoneLookupResult to parse the response JSON in data Result class. Result resultData = ParsePhoneLookupResult(responseInJson); if (resultData != null) { // Calling function to populate data on UI. PopulateDataOnUI(resultData); } } else { this.ResultDiv.Visible = false; this.errorBox.Visible = true; this.LiteralErrorMessage.Text = errorMessage; } } else { this.ResultDiv.Visible = false; this.errorBox.Visible = true; this.LiteralErrorMessage.Text = WhitePagesConstants.PhoneBlankInputMessage; } } catch (Exception ex) { this.ResultDiv.Visible = false; this.errorBox.Visible = true; this.LiteralErrorMessage.Text = ex.Message; } }
/// <summary> /// Event occurs when the Button control is clicked. /// Here we will call person lookup API, parse result and populate result on UI /// </summary> /// <param name="sender">Object sender</param> /// <param name="e">event data.</param> protected void ButtonFindClick(object sender, EventArgs e) { try { this.errorDiv.Visible = false; this.LitralErrorMessage.Text = string.Empty; // Calling ValidateInput method to validate user's input. bool isInputValidated = ValidateInput(); if (!isInputValidated) { this.errorDiv.Visible = true; return; } int statusCode = -1; string description = string.Empty; string errorMessage = string.Empty; NameValueCollection nameValues = new NameValueCollection(); nameValues["first_name"] = person_first_name.Text; nameValues["last_name"] = person_last_name.Text; nameValues["address"] = person_where.Text; nameValues["api_key"] = WhitePagesConstants.ApiKey; WhitePagesWebService webService = new WhitePagesWebService(); // Call method ExecuteWebRequest to execute backend API and return response stream. Stream responseStream = webService.ExecuteWebRequest(nameValues, ref statusCode, ref description, ref errorMessage); // Checking respnseStream null and status code. if (statusCode == 200 && responseStream != null) { // Reading response stream to StreamReader. StreamReader reader = new StreamReader(responseStream); // Convert stream reader to string JSON. string responseInJson = reader.ReadToEnd(); // Dispose the response stream. responseStream.Dispose(); // Calling ParsePersonLookupResult to parse the response and return result data. Result result = ParsePersonLookupResult(responseInJson); if (result != null && result.GetPerson() != null && result.GetPerson().Length > 0) { // Calling function to populate data on UI. PopulateDataOnUI(result); } } else { this.personResult.Visible = false; this.errorDiv.Visible = true; this.LitralErrorMessage.Text = errorMessage; } } catch (Exception ex) { this.errorDiv.Visible = true; this.LitralErrorMessage.Text = ex.Message; } }