Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetCompany([FromUri] string cnpj)
        {
            var company = CNPJ.SearchCNPJ(cnpj);

            if (!company.IsError)
            {
                return(Ok(new Company()
                {
                    Activity = company.AtividadePrincipal.First().Text,
                    Cnpj = company.Cnpj,
                    FantasyName = !string.IsNullOrWhiteSpace(company.Fantasia)
                                    ? company.Fantasia : company.Nome,
                    Person = new Person()
                    {
                        City = new City()
                        {
                            Name = company.Municipio,
                            State = new State()
                            {
                                Initials = company.Uf
                            }
                        },
                        Name = company.Nome,
                        Address = company.Logradouro,
                        Number = company.Numero,
                        Act = true,
                        Phones = company.Telefone.Split('/').Select((t, i) => new Phone()
                        {
                            IsMain = i == 0,
                            Contact = company.Qsa[i]?.Nome ?? "",
                            PhoneNumber = t.Trim()
                        })
                                 .ToList()
                    }
                }));
            }
            return(BadRequest("CNPJ: <strong>" + cnpj + "</strong> não encontrado."));
        }