public ActionResult Save(CnpjFormViewModel modelo) { ApiObjeto apiObjeto = modelo.Empresa; obSave = apiObjeto; _cnpjService.Insert(obSave); return(RedirectToAction(nameof(Index))); }
public IActionResult Cnpj(string txtCep) { if (txtCep == null) { TempData["erro"] = "Digite um numero valido"; return(RedirectToAction(nameof(Index))); } txtCep = txtCep.Replace(".", "").Replace("-", "").Replace("/", "").Replace(" ", ""); string apiUrl = "https://www.receitaws.com.br/v1/cnpj/" + txtCep; var ApiObjeto = new ApiObjeto(); using (HttpClient client = new HttpClient()) { var response = client.GetAsync(apiUrl).Result; var resposta = response.Content.ReadAsStringAsync().Result; ApiObjeto = Newtonsoft.Json.JsonConvert.DeserializeObject <ApiObjeto>(resposta); } if (ApiObjeto.Message != null) { TempData["erro"] = ApiObjeto.Message; return(RedirectToAction(nameof(Index))); } else { //ViewData.Add("ApiObjeto", ApiObjeto); ViewBag.ApiObjeto = ApiObjeto; var viewModel = new CnpjFormViewModel { Empresa = ApiObjeto, Atividade_principal = ApiObjeto.Atividade_principal, Atividade_secundaria = ApiObjeto.atividades_secundarias, Socio_adm = ApiObjeto.Qsa, }; return(View(viewModel)); } }
public void Insert(ApiObjeto obj) { _context.Add(obj); _context.SaveChanges(); }