public IActionResult ConsultarFinanceiro(Guid id) { var x = _propostaAppService.ObterPorId(id); string uri = "http://www.mbm.net.br/wsSisPrev/"; string token = ""; string username = "******"; string password = "******"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); HttpResponseMessage response = client.PostAsync("Token", new StringContent(string.Format("grant_type=password&username={0}&password={1}", HttpUtility.UrlEncode(username), HttpUtility.UrlEncode(password)), Encoding.UTF8, "application/x-www-form-urlencoded")).Result; string resultJSON = response.Content.ReadAsStringAsync().Result; string[] partes = resultJSON.Split('"'); TokenResultViewModel tk = new TokenResultViewModel(); TokenToDeseralize tokkk = JsonConvert.DeserializeObject <TokenToDeseralize>(resultJSON); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokkk.AccessToken); HttpResponseMessage xresponse = client.GetAsync(uri + "Api/propostas/" + x.Pronum).Result; if (response.IsSuccessStatusCode) { var jsonString = xresponse.Content.ReadAsStringAsync(); } return(View("Index", _propostaAppService.ObterTodos())); }
public void Registrar(TokenResultViewModel tokenViewModel) { var registroCommand = _mapper.Map <RegistrarTokenCommand>(tokenViewModel); _bus.SendCommand(registroCommand); }
public IActionResult Index() { var x = _tokenAppService.ObterTodos(); if (x.Any()) { var v = x.FirstOrDefault(); if (v.LimiteDoToken > DateTime.Now) { retornoJsonAsync(v.RETORNOTOTAL, "http://www.mbm.net.br/wsSisPrev/"); return(View()); } else { _tokenAppService.Excluir(v.Id); string uri = "http://www.mbm.net.br/wsSisPrev/"; string token = ""; string username = "******"; string password = "******"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); HttpResponseMessage response = client.PostAsync("Token", new StringContent(string.Format("grant_type=password&username={0}&password={1}", HttpUtility.UrlEncode(username), HttpUtility.UrlEncode(password)), Encoding.UTF8, "application/x-www-form-urlencoded")).Result; string resultJSON = response.Content.ReadAsStringAsync().Result; string[] partes = resultJSON.Split('"'); TokenResultViewModel tk = new TokenResultViewModel(); TokenToDeseralize tokkk = JsonConvert.DeserializeObject <TokenToDeseralize>(resultJSON); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokkk.AccessToken); HttpResponseMessage xresponse = client.GetAsync(uri + "Api/dados/tipoenvio").Result; if (response.IsSuccessStatusCode) { var jsonString = xresponse.Content.ReadAsStringAsync(); } tk.AccessToken = tokkk.AccessToken; tk.RETORNOTOTAL = resultJSON; tk.Error = "Erro"; tk.ErrorDescription = "Erro"; var t = Convert.ToDateTime(partes[21]); tk.LimiteDoToken = t.ToUniversalTime(); _tokenAppService.Registrar(tk); return(View()); } } else { return(View()); } }
public void Atualizar(TokenResultViewModel clienteViewModel) { var atualizarToken = _mapper.Map <AtualizarTokenCommand>(clienteViewModel); _bus.SendCommand(atualizarToken); }