Пример #1
0
        public IHttpActionResult GetCorpoElec(string _userNic)
        {
            try
            {
                value            = $"?nic={_userNic}";
                url              = new Uri($"{MethodsHelper.GetUlrCorpoElect()}{value}");
                restClient       = new RestClient(url);
                this.restRequest = new RestRequest(Method.POST);
                this.restRequest.AddHeader(
                    "cache-control",
                    "no-cache");
                this.iRestResponse = restClient.Execute(this.restRequest);

                servicesVzLaCorpoElect = new ServicesVzLaCorpoElect();

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

                        //  Get the header data
                        this.listDataA = this.htmlDocument.DocumentNode.Descendants("td")
                                         .ToList();

                        foreach (var listItemDataA in this.listDataA)
                        {
                            if (listItemDataA.InnerText.Contains("NIC:"))
                            {
                                this.listDataB = listItemDataA.DescendantsAndSelf("input")
                                                 .Where(node => !string.IsNullOrWhiteSpace(node.Id) &&
                                                        node.Attributes["value"] != null)
                                                 .ToList();

                                servicesVzLaCorpoElect.NicUsuario = this.listDataB[0].Attributes["value"].Value;
                            }

                            if (listItemDataA.InnerText.Contains("USUARIO:"))
                            {
                                this.listDataB = listItemDataA.DescendantsAndSelf("input")
                                                 .Where(node => !string.IsNullOrWhiteSpace(node.Id) &&
                                                        node.Attributes["value"] != null)
                                                 .ToList();
                                servicesVzLaCorpoElect.NombreUsuario = this.listDataB[0].Attributes["value"].Value;
                            }

                            if (listItemDataA.InnerText.Contains("DEUDA PENDIENTE DEL USUARIO"))
                            {
                                this.listDataB = listItemDataA.DescendantsAndSelf("input")
                                                 .Where(node => !string.IsNullOrWhiteSpace(node.Id) &&
                                                        node.Attributes["value"] != null)
                                                 .ToList();
                                servicesVzLaCorpoElect.DeudaPendienteUsuario = this.listDataB[0].Attributes["value"].Value;
                            }

                            if (listItemDataA.InnerText.Contains("Deuda Vencida"))
                            {
                                this.listDataB = listItemDataA.DescendantsAndSelf("input")
                                                 .Where(node => !string.IsNullOrWhiteSpace(node.Id) &&
                                                        node.Attributes["value"] != null)
                                                 .ToList();
                                servicesVzLaCorpoElect.DeudaVencidaUsuario = this.listDataB[0].Attributes["value"].Value;
                            }
                        }

                        //  Get the details data
                        this.listDataA = this.htmlDocument.DocumentNode.Descendants("td")
                                         .Where(node => node.GetAttributeValue("style", "")
                                                .Equals("HEIGHT: 71px"))
                                         .ToList();

                        if (this.listDataA.Count > 0)
                        {
                            this.InitialFieldCorpoElectDetail();
                            lcAux001 = string.Empty;
                            lnAux001 = 0;
                            servicesVzLaCorpoElectDetails = new List <ServicesVzLaCorpoElectDetails>();

                            this.listDataB = this.listDataA[0].Descendants("td")
                                             .ToList();
                            foreach (var listItemDataB in this.listDataB)
                            {
                                if (listItemDataB.InnerText.ToString() == "Total Factura")
                                {
                                    lcAux001 = listItemDataB.InnerText.ToString();
                                }

                                if (lcAux001 == listItemDataB.InnerText.ToString())
                                {
                                }
                                else
                                {
                                    if (lcAux001 == "Total Factura")
                                    {
                                        switch (lnAux001)
                                        {
                                        case 0:
                                            this.simboloVariable = listItemDataB.InnerText.Trim();
                                            break;

                                        case 1:
                                            this.fechaEmision = listItemDataB.InnerText.Trim();
                                            break;

                                        case 2:
                                            this.fechaVencimiento = listItemDataB.InnerText.Trim();
                                            break;

                                        case 3:
                                            this.importeEnergia = listItemDataB.InnerText.Trim();
                                            break;

                                        case 4:
                                            this.importeAseo = listItemDataB.InnerText.Trim();
                                            break;

                                        case 5:
                                            this.totalFactura = listItemDataB.InnerText.Trim();

                                            this.servicesVzLaCorpoElectDetails.Add(
                                                new ServicesVzLaCorpoElectDetails
                                            {
                                                FechaEmision     = this.fechaEmision,
                                                FechaVencimiento = this.fechaVencimiento,
                                                ImporteAseo      = this.importeAseo,
                                                ImporteEnergia   = this.importeEnergia,
                                                SimboloVariable  = this.simboloVariable,
                                                TotalAseo        = this.importeAseo,
                                            });
                                            lnAux001 = -1;
                                            this.InitialFieldCorpoElectDetail();
                                            break;
                                        }

                                        lnAux001++;
                                    }
                                }
                            }
                            servicesVzLaCorpoElect.Details = this.servicesVzLaCorpoElectDetails;
                        }
                    }
                    else
                    {
                        //  Ojo aqui
                    }
                }
                else
                {
                    //  Ojo aqui
                }

                return(Ok(servicesVzLaCorpoElect));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                servicesVzLaCorpoElect.Error       = true;
                servicesVzLaCorpoElect.Descripcion = ex.Message;
                return(Ok(servicesVzLaCorpoElect));
            }
        }