예제 #1
0
    public DataTable GETCEP(string pCEP, string pToken, string pIsDeliveryRequest, int pIdCourier)
    {
        DataTable lResult;

        try
        {
            if (ValidaToken(pToken))
            {
                CEP lCep = new CEP();

                string lCleanUserZipCode = pCEP.Replace("-", "").Replace("'", "");

                if (pIsDeliveryRequest == string.Empty)
                {
                    pIsDeliveryRequest = "0";
                }

                if (pIsDeliveryRequest == "1")
                {
                    if (lCep.CourierCanDeliver(lCleanUserZipCode, LocalInstance.ConnectionInfo))
                    {
                        lResult = lCep.GetDeliveryAddressByZipCode(lCleanUserZipCode, Convert.ToInt32(pIsDeliveryRequest), pIdCourier, LocalInstance.ConnectionInfo);
                    }
                    else
                    {
                        lResult = new DataTable("ERRO");
                        lResult.Columns.Add("MENSAGEM");
                        DataRow lRow = lResult.NewRow();
                        lRow["MENSAGEM"] = "A Empresa courier não realiza entregas no endereço solicitado.";
                        lResult.Rows.Add(lRow);
                    }
                }
                else
                {
                    lResult = lCep.GetDeliveryAddressByZipCode(lCleanUserZipCode, Convert.ToInt32(pIsDeliveryRequest), pIdCourier, LocalInstance.ConnectionInfo);
                }
            }
            else
            {
                lResult = new DataTable("ERRO");

                lResult.Columns.Add("MENSAGEM");
                DataRow lRow = lResult.NewRow();
                lRow["MENSAGEM"] = "Token Incorreto";
                lResult.Rows.Add(lRow);
            }
        }
        catch (Exception lEx)
        {
            lResult = new DataTable("ERRO");

            lResult.Columns.Add("MENSAGEM");
            DataRow lRow = lResult.NewRow();
            lRow["MENSAGEM"] = lEx.Message;
            lResult.Rows.Add(lRow);
        }

        return(lResult);
    }