private async void FindDataCne() { // Sets status of controls this.SetStatusControl(false, true, "Green", 1); // Validate the connections of internet var response = await this.apiService.CheckConnection(); if (!response.IsSuccess) { // Sets status of controls this.SetStatusControl(false, false, "Green", 0); await this.dialogService.ShowMessage( "Error", response.Message, "Accept"); return; } // Define the url parameter var ulrParameter = string.Format( "/{0}/{1}", this.cneItemViewModel.NationalityDatas[0].Abbreviation, this.cneItemViewModel.IdentificationCard); // Get data of the cne api response = await apiService.Get <Cne>( MethodsHelper.GetUrlCne(), "/infove/cne", "/elector", ulrParameter); if (!response.IsSuccess) { // Sets status of controls this.SetStatusControl(false, false, "Green", 0); await this.dialogService.ShowMessage( "Error", response.Message, "Accept"); return; } // Load values in the control this.LoadValuesControls(1, (Cne)response.Result); // Sets status of controls if (isValid) { this.SetStatusControl(true, false, "Green", 0); } }
public IHttpActionResult GetCneData( string _nationalityUser, int _numberUser ) { try { value = $"?nacionalidad={_nationalityUser}&cedula={_numberUser}"; // url = new Uri($"http://www.cne.gob.ve/web/registro_electoral/ce.php{value}"); this.url = new Uri($"{MethodsHelper.GetUrlCne()}{value}"); this.restClient = new RestClient(url); this.restRequest = new RestRequest(Method.POST); this.restRequest.AddHeader( "cache-control", "no-cache"); this.iRestResponse = restClient.Execute(this.restRequest); servicesVzLaCne = new ServicesVzLaCne(); if (this.iRestResponse != null && !string.IsNullOrEmpty(this.iRestResponse.Content)) { this.htmlDocument = new HtmlDocument(); this.htmlDocument.LoadHtml(this.iRestResponse.Content); // Get data primary this.listDataA = this.htmlDocument.DocumentNode.Descendants("table") .Where(node => node.GetAttributeValue("cellpadding", "") .Equals("2")).ToList(); // Get data secundary this.listDataB = this.htmlDocument.DocumentNode.Descendants("td") .Where(node => node.GetAttributeValue("align", "") .Equals("center")).ToList(); if (this.listDataB.Count > 0) { foreach (var listItemB in this.listDataB) { this.listDataC = listItemB.Descendants("b") .ToList(); if (this.listDataC.Count > 0 && !listItemB.InnerText.Contains("DATOS DEL ELECTOR") && !listItemB.InnerText.Contains("Conoce los Miembros de Mesa de tu Centro de Votación.")) { servicesVzLaCne.Mensaje = string.Format( string.IsNullOrEmpty(servicesVzLaCne.Mensaje) ? "{0}{1}" : "{0}; {1}", servicesVzLaCne.Mensaje, listItemB.InnerText.Trim()); } } } lcAux001 = string.Empty; lnAux001 = 0; if (this.listDataA.Count > 0) { //foreach (var lustItemA in this.listDataA) //{ //if(lnAux001 == 0) //{ this.listDataC = this.listDataA[0].Descendants("td") .Where(node => node.GetAttributeValue("align", "") .Equals("left")).ToList(); if (this.listDataC.Count > 0) { lnAux001 = 0; foreach (var listItemC in this.listDataC) { if ((lnAux001 % 2) == 0) { lcAux001 = listItemC.InnerText.Trim(); } else { switch (lcAux001) { case "Cédula:": servicesVzLaCne.Cedula = listItemC.InnerText.Trim(); break; case "Nombre:": servicesVzLaCne.Nombre = listItemC.InnerText.Trim(); break; case "Estado:": servicesVzLaCne.Estado = listItemC.InnerText.Trim(); break; case "Municipio:": servicesVzLaCne.Municipio = listItemC.InnerText.Trim(); break; case "Parroquia:": servicesVzLaCne.Parroquia = listItemC.InnerText.Trim(); break; case "Centro:": servicesVzLaCne.Centro = listItemC.InnerText.Trim(); break; case "Dirección:": servicesVzLaCne.Direccion = listItemC.InnerText.Trim(); break; } } lnAux001++; } return(Ok(servicesVzLaCne)); } else { this.listDataB = this.listDataA[0].Descendants("td") .Where(node => node.GetAttributeValue("colspan", "") .Equals("3")).ToList(); foreach (var lisItemDataB in this.listDataB) { if (!string.IsNullOrEmpty(lisItemDataB.InnerText)) { servicesVzLaCne.Descripcion += lisItemDataB.InnerText + Char.ConvertFromUtf32(13); } } servicesVzLaCne.Error = true; ModelState.AddModelError(string.Empty, servicesVzLaCne.Descripcion); return(Ok(servicesVzLaCne)); } //} // lnAux001++; //} } else { // Get error consult this.listDataA = this.htmlDocument.DocumentNode.Descendants("table") .Where(node => node.GetAttributeValue("align", "") .Equals("center")).ToList(); foreach (var listItemA in this.listDataA) { this.listDataB = listItemA.Descendants("td") .ToList(); if (this.listDataB.Count > 0) { servicesVzLaCne.Descripcion += this.listDataB[0].InnerText + Char.ConvertFromUtf32(13); } // lcAux001 = listItemA.InnerText; } servicesVzLaCne.Error = true; ModelState.AddModelError(string.Empty, servicesVzLaCne.Descripcion); return(Ok(servicesVzLaCne)); } } servicesVzLaCne.Error = true; if (this.iRestResponse.ErrorException == null) { ModelState.AddModelError(string.Empty, "No data found...!!!"); servicesVzLaCne.Descripcion = "No data found...!!!"; } else { // Get error request servicesVzLaCne.Descripcion = this.iRestResponse.ErrorException.Message + Char.ConvertFromUtf32(13); if (this.iRestResponse.ErrorException.InnerException != null) { servicesVzLaCne.Descripcion += this.iRestResponse.ErrorException.InnerException.Message; } } return(Ok(servicesVzLaCne)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); servicesVzLaCne.Error = true; servicesVzLaCne.Descripcion = ex.Message; return(Ok(servicesVzLaCne)); } }