public string IniciarRastreioLogComex(BlMaster bl) { var token = ""; string Url = "https://api.logcomex.io/api/v3/"; string apiKey = "7b86d436a5d89ac4c8be11553b432bad"; //var nbl = new BL { BlNUmber = "123456", BlTOken = "", Id = 0, PartnerIdCustomer = 0 }; dynamic campos = null; campos = new { bl_number = bl.NR_BL, reference = "", consignee_cnpj = _configuration.GetSection("LogComex").GetSection("consignee_cnpj").Value, emails = _configuration.GetSection("LogComex").GetSection("email").Value, shipowner = bl.ID_ARMADOR_LOGCOMEX }; var jsonString = JsonConvert.SerializeObject(campos); Task <string> response = _logComexRepositorio.ApiLogComex(Url, apiKey, jsonString); //dynamic jsonResponse = JsonConvert.DeserializeObject(response); var tokenResponse = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Result); foreach (KeyValuePair <string, string> item in tokenResponse) { if (item.Key == "token") { token = item.Value; } } return(token); }
public async Task <string> IniciarRastreioBl(BlMaster bl) { var token = ""; string Url = ConfigurationManager.AppSettings["baseUrl"]; string apiKey = ConfigurationManager.AppSettings["apiKey"]; dynamic campos = null; campos = new { bl_number = bl.NR_BL, reference = "", consignee_cnpj = ConfigurationManager.AppSettings["cnpj"], emails = ConfigurationManager.AppSettings["email"], shipowner = bl.ID_ARMADOR_LOGCOMEX }; var jsonString = JsonConvert.SerializeObject(campos); Task <string> response = await _logcomex_repositorio.ApiLogComex(Url, apiKey, jsonString); //dynamic jsonResponse = JsonConvert.DeserializeObject(response); var tokenResponse = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Result); foreach (KeyValuePair <string, string> item in tokenResponse) { if (item.Key == "token") { token = item.Value; } } return(token); }
public IActionResult IniciarRastreioBL([FromBody] BlMaster bl) { if (bl.NR_BL == null) { var listBl = _repositorio_bl.ListarTodas(); foreach (var item in listBl) { if (item.BL_TOKEN == null || item.BL_TOKEN == "") { bl = new BlMaster { NR_BL = item.NR_BL, ID_ARMADOR_LOGCOMEX = item.ID_ARMADOR_LOGCOMEX }; var token1 = _servico_logcomex.IniciarRastreioLogComex(bl); if (token1 != "") { bl.BL_TOKEN = token1; _repositorio_bl.CadastrarTokenBl(bl); _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); } } else { bl = new BlMaster { NR_BL = item.NR_BL, BL_TOKEN = item.BL_TOKEN }; _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); } } } else { var token = _servico_logcomex.IniciarRastreioLogComex(bl); if (token != "") { try { bl.BL_TOKEN = token; _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); _repositorio_bl.CadastrarTokenBl(bl); } catch (Exception ex) { throw ex; } } }; return(Ok()); }
public IActionResult Listar() { List <object> list = new List <object>(); var query = _repositorio_bl.ListarTodas().ToList(); foreach (var item in query) { try { BlMaster bl = new BlMaster(); if (bl != null) { bl.BL_TOKEN = item.BL_TOKEN; bl.ID_ARMADOR_LOGCOMEX = item.ID_ARMADOR_LOGCOMEX; bl.TRAKING_BL = item.TRAKING_BL; bl.NR_BL = item.NR_BL; IniciarRastreioBL(bl); } } catch (Exception ex) { ex.ToString(); } } //var queryHouse = _repositorio_bl_house.GetAllDadosBlHouse().ToList(); //foreach (var itemIn in queryHouse) //{ // BlHouse blHouse = new BlHouse(); // blHouse.BL_TOKEN = itemIn.BL_TOKEN; // blHouse.ID_ARMADOR_LOGCOMEX = itemIn.ID_ARMADOR_LOGCOMEX; // blHouse.TRAKING_BL = itemIn.TRAKING_BL; // blHouse.NR_BL = itemIn.NR_BL; // IniciarRastreioBLHouse(blHouse); //} //list.AddRange(query.ToList()); //list.AddRange(queryHouse.ToList()); return(Ok(list)); }
public void AtualizarBlTraking(BlMaster bl) { var connectionString = this.GetConnection(); var count = 0; using (var con = new SqlConnection(connectionString)) { try { con.Open(); var query = "UPDATE TB_BL SET TRAKING_BL = '" + bl.TRAKING_BL.Replace("'", "") + "' WHERE BL_TOKEN = '" + bl.BL_TOKEN + "'"; count = con.Execute(query, bl); } catch (Exception ex) { throw ex; } finally { con.Close(); } } }
public void CadastrarTokenBl(BlMaster bl) { var connectionString = this.GetConnection(); var count = 0; using (var con = new SqlConnection(connectionString)) { try { con.Open(); var query = "UPDATE TB_BL SET BL_TOKEN = '" + bl.BL_TOKEN + "' WHERE NR_BL = '" + bl.NR_BL + "'"; count = con.Execute(query, bl); } catch (Exception ex) { throw ex; } finally { con.Close(); } } }
public HttpResponseMessage Post([FromBody] BlMaster bl) { _servico_logcomex.IniciarRastreioBl(bl); return(Request.CreateResponse("tudo certo")); }
public BlMaster CadastrarTokenBl(BlMaster bl) { throw new NotImplementedException(); }