Ejemplo n.º 1
0
        /// <summary>
        /// Search address by Zip Code
        /// </summary>
        /// <param name="zipCode">Zip code value</param>
        /// <param name="type">The type to search address. Use ViaCEPTypes object to help. Possible values include: 'json', 'xml', 'piped' and 'querty'</param>
        /// <returns>String with result in type selected</returns>
        ///
        public static string ByZipCode(int zipCode, string type)
        {
            try
            {
                var result = ViaCEPServices.GetAddressByCEP(zipCode, type);

                return(result);
            }
            catch (CEPLibraryException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new CEPLibraryException(ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search address by Zip Code
        /// </summary>
        /// <param name="zipCode">Zip code value</param>
        /// <returns>Object with address result</returns>
        public static ViaCEPModel ByZipCode(int zipCode)
        {
            try
            {
                var jsonResult = ViaCEPServices.GetAddressByCEP(zipCode, ViaCEPTypes.Json);

                var objectResult = JsonConvert.DeserializeObject <ViaCEPModel>(jsonResult);

                return(objectResult);
            }
            catch (CEPLibraryException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new CEPLibraryException(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void BuscaCEP(Object sender, EventArgs args)
        {
            if (IsValidCEP(txtCEP.Text))
            {
                try
                {
                    Endereco end = ViaCEPServices.BuscarEnderecoViaCEP(txtCEP.Text);

                    if (end != null)
                    {
                        lblResultado.Text = string.Format("Endereço: {0} - {1} {2}/{3}", end.logradouro, end.bairro, end.localidade, end.uf);
                    }
                    else
                    {
                        DisplayAlert("Erro", "Endereço não encontrado para o CEP informado", "OK");
                    }
                }catch (Exception e)
                {
                    DisplayAlert("Erro", "Não foi possível buscar o CEP, segue:" + e.Message, "OK");
                }
            }
        }