private async void FindDataCantv()
        {
            //  Asing status to the controls
            this.SetStatusControl(false, true, 1);

            //  Validat if the connection es successfully
            var response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Asing status to the controls
                SetStatusControl(false, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                //  Navigate on back
                GoBack();
                return;
            }

            //  Gets the data of Cantv
            //response = await apiService.Get<Cantv>(
            //MethodsHelper.GetUrlCantv(),
            //"/infove/cantv",
            //"/deuda",
            //string.Format(
            //"/{0}/{1}",
            //this.cantvItemView.CodePhone,
            //this.cantvItemView.NumberPhone));

            response = await apiService.Get <Cantv>(
                MethodsHelper.GetUrlCantv(),
                "/API",
                "/WebServices/GetCantvData",
                string.Format(
                    "?_numberCode={0}&_numberPhone={1}",
                    this.cantvItemView.CodePhone,
                    this.cantvItemView.NumberPhone));

            if (!response.IsSuccess)
            {
                //  Asing status to the controls
                this.SetStatusControl(false, false, 0);

                if (response.Message.Contains(
                        "No se ha indicado el número de teléfono"))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "No se ha indicado el número de télefono",
                        "Accept");
                }
                else
                {
                    await dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");
                }

                //  Navigate on Back
                this.GoBack();
                return;
            }
            else
            {
                var cantv = (Cantv)response.Result;
                if (cantv.Error && !string.IsNullOrEmpty(cantv.Descripcion))
                {
                    //  Asing status to the controls
                    this.SetStatusControl(false, false, 0);

                    await dialogService.ShowMessage(
                        "Error",
                        cantv.Descripcion,
                        "Accept");

                    //  Navigate on Back
                    this.GoBack();
                    return;
                }
            }

            //  Load values in the controsl
            this.LoadValuesControls((Cantv)response.Result, 1);

            //  Asing status to the controls
            this.SetStatusControl(false, false, 0);
        }
示例#2
0
        public IHttpActionResult GetCantvData(
            int _numberCode,
            int _numberPhone)
        {
            try
            {
                url              = new Uri(MethodsHelper.GetUrlCantv());
                value            = $"sarea={_numberCode}&stelefono={_numberPhone}";
                restClient       = new RestClient(url);
                this.restRequest = new RestRequest(Method.POST);
                this.restRequest.AddHeader(
                    "cache-control",
                    "no-cache");
                this.restRequest.AddHeader(
                    "content-type",
                    "application/x-www-form-urlencoded");
                this.restRequest.AddParameter(
                    "application/x-www-form-urlencoded",
                    value,
                    ParameterType.RequestBody);
                this.iRestResponse = restClient.Execute(this.restRequest);
                servicesVzLaCantv  = new ServicesVzLaCantv();

                if (this.iRestResponse != null ||
                    !string.IsNullOrEmpty(this.iRestResponse.Content))
                {
                    this.htmlDocument = new HtmlDocument();
                    this.htmlDocument.LoadHtml(this.iRestResponse.Content);

                    listDataError = this.htmlDocument.DocumentNode.Descendants("table")
                                    .Where(node => node.GetAttributeValue("width", "")
                                           .Equals("350")).ToList();

                    errorMessage = listDataError
                                   .Where(lde => lde.InnerText.Trim().Contains("Numero invalido"))
                                   .FirstOrDefault();

                    this.listDataA = this.htmlDocument.DocumentNode.Descendants("body")
                                     .Where(node => node.GetAttributeValue("table", "")
                                            .Equals("")).ToList();

                    lcAux001 = string.Empty;
                    lnAux001 = 0;

                    if (this.listDataA.Count > 0)
                    {
                        foreach (var listItemA in this.listDataA)
                        {
                            if (lnAux001 == 1)
                            {
                                this.listDataB = listItemA.Descendants("font")
                                                 .Where(node => node.GetAttributeValue("face", "")
                                                        .Equals("Verdana, Arial, Helvetica, sans-serif")).ToList();

                                if (this.listDataB.Count > 0)
                                {
                                    lnAux001 = 0;

                                    foreach (var listItemB in this.listDataB)
                                    {
                                        if ((lnAux001 % 2) == 0)
                                        {
                                            lcAux001 = listItemB.InnerText.Trim();
                                        }
                                        else
                                        {
                                            switch (lcAux001)
                                            {
                                            case "Saldo actual Bs.":
                                                servicesVzLaCantv.SaldoActual = listItemB.InnerText.Trim();
                                                break;

                                            case "Fecha de &uacute;ltima facturaci&oacute;n:":
                                                servicesVzLaCantv.UltimaFacturacion = listItemB.InnerText.Trim();
                                                break;

                                            case "Fecha corte:":
                                                servicesVzLaCantv.FechaCorte = listItemB.InnerText.Trim();
                                                break;

                                            case "Fecha de vencimiento:":
                                                servicesVzLaCantv.FechaVencimiento = listItemB.InnerText.Trim();
                                                break;

                                            case "Saldo vencido:":
                                                servicesVzLaCantv.SaldoVencido = listItemB.InnerText.Trim();
                                                break;

                                            case "Monto del &uacute;ltimo pago realizado:":
                                                servicesVzLaCantv.UltimoPago = listItemB.InnerText.Trim();
                                                break;
                                            }
                                        }
                                        lnAux001++;
                                    }

                                    if (errorMessage != null)
                                    {
                                        servicesVzLaCantv.Error       = true;
                                        servicesVzLaCantv.Descripcion = "Invalid number...!!!";
                                    }

                                    return(Ok(servicesVzLaCantv));
                                }
                            }
                            lnAux001++;
                        }
                    }
                }

                //  ModelState.AddModelError(string.Empty, "Not data found...!!!");
                //  return BadRequest(ModelState);

                servicesVzLaCantv.Error       = true;
                servicesVzLaCantv.Descripcion = "Not data found...!!!";
                return(Ok(servicesVzLaCantv));
            }
            catch (Exception ex)
            {
                //ModelState.AddModelError(string.Empty, ex.Message);
                //return BadRequest(ModelState);
                return(Ok(new ServicesVzLaCantv
                {
                    Descripcion = ex.Message,
                    Error = true,
                }));
            }
        }