public string IniciarRastreioBLHouseLogComex(BlHouse bl) { var token = ""; string Url = "https://api.logcomex.io/api/v3"; string apiKey = "7b86d436a5d89ac4c8be11553b432bad"; 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); 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 IniciarRastreioBLHouse([FromBody] BlHouse bl) { if (bl.NR_BL == null) { var listBLHouse = _repositorio_bl_house.GetAllDadosBlHouse(); foreach (var item in listBLHouse) { if (item.BL_TOKEN == null || item.BL_TOKEN == "") { bl = new BlHouse { NR_BL = item.NR_BL, ID_ARMADOR_LOGCOMEX = item.ID_ARMADOR_LOGCOMEX, }; var token_ = _servico_logcomex.IniciarRastreioBLHouseLogComex(bl); if (token_ != "") { bl.BL_TOKEN = token_; _repositorio_bl_house.CadastrarTokenBLHouse(bl); _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); } } else { bl = new BlHouse { NR_BL = bl.NR_BL, BL_TOKEN = bl.BL_TOKEN, }; _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); } } } else { var token__ = _servico_logcomex.IniciarRastreioBLHouseLogComex(bl); if (token__ != "") { try { bl.BL_TOKEN = token__; _servico_logcomex.AtualizarRastreamentoLogComex(bl.BL_TOKEN); _repositorio_bl_house.CadastrarTokenBLHouse(bl); } catch (Exception ex) { throw ex; } } } return(Ok()); }
public void AtualizarBLTrackingHouse(BlHouse bl) { try { using (var con = new SqlConnection(Conexao())) { StringBuilder sb = new StringBuilder(); sb.AppendLine(" UPDATE TB_BL SET TRAKING_BL = '" + bl.TRAKING_BL.Replace("'", "") + "' WHERE BL_TOKEN = '" + bl.BL_TOKEN + "' "); con.Query <BlHouse>(sb.ToString()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } }
public void CadastrarTokenBLHouse(BlHouse bl) { try { using (var con = new SqlConnection(Conexao())) { StringBuilder sb = new StringBuilder(); sb.AppendLine(" UPDATE TB_BL SET BL_TOKEN = '" + bl.BL_TOKEN + "' WHERE NR_BL = '" + bl.NR_BL + "' "); con.Query <BlHouse>(sb.ToString()).FirstOrDefault(); } } catch (Exception ex) { throw ex; } }