public async Task <IActionResult> OnGetAsync(string id) { var t = await _empresaApp.GetCnpjAsync(id); Input = t; return(Page()); }
/** Consulta RFB **/ public async Task <BaseReceitaFederal> GetCnpjAsync(string cnpj) { var brf = new BaseReceitaFederal(); var t = Task.Run(() => { var cnpjbase = cnpj.Remove(8, 6); var cnpjordem = cnpj.Remove(0, 8); cnpjordem = cnpjordem.Remove(4, 2); var cnpjdv = cnpj.Remove(0, 12); var qry = (from est in db.Estabelecimentos from atv in db.CNAEs .Where(s => est.CnaeFiscalPrincipal == s.Codigo) from msc in db.MotivoSituacaoCadastral .Where(s => est.MotivoSituacaoCadastral == s.Codigo) from mnp in db.Municipios .Where(s => est.Municipio == s.Codigo) from emp in db.Empresas .Where(s => est.CNPJBase == s.CNPJBase) from ntj in db.NaturezaJuridica .Where(s => emp.NaturezaJuridica == s.Codigo) from qsa in db.QualificacaoSocios .Where(s => emp.QualificacaoResponsavel == s.Codigo) from snp in db.Simples .Where(s => est.CNPJBase == s.CNPJBase).DefaultIfEmpty() select new { est, atv, msc, mnp, emp, ntj, qsa, snp }) .Where(s => s.est.CNPJBase == cnpjbase && s.est.CNPJOrdem == cnpjordem && s.est.CNPJDV == cnpjdv).Distinct(); foreach (var e in qry) { var _cnpj = string.Format("{0}{1}{2}", e.est.CNPJBase, e.est.CNPJOrdem, e.est.CNPJDV); var qrysco = (from sco in db.Socios from qsco in db.QualificacaoSocios .Where(s => sco.QualificacaoSocio == s.Codigo) from qscoresp in db.QualificacaoSocios .Where(s => sco.QualificacaoRepresentanteLegal == s.Codigo) select new { sco, qsco }) .Where(s => s.sco.CNPJBase == e.est.CNPJBase).Distinct(); var socios = new List <Socio>(); foreach (var q in qrysco) { socios.Add(new Socio(q.sco.CNPJBase, q.sco.IdentificadorSocio, q.sco.NomeRazaoSocio, q.sco.CnpjCpfSocio , q.qsco.Descricao, q.sco.DataEntradaSociedade, q.sco.Pais, q.sco.RepresentanteLegal, q.sco.NomeRepresentante , q.qsco.Descricao, q.sco.FaixaEtaria)); } brf = new BaseReceitaFederal( 0, _cnpj, e.emp, e.est, socios, e.snp, e.atv, null, e.ntj, e.msc, e.mnp, e.qsa); } }); await t; return(brf); }