Ejemplo n.º 1
0
        public async void Institutos(string token)
        {
            InstitutoApi     _Institutos   = new InstitutoApi();
            InstitutoService service       = new InstitutoService();
            List <Instituto> listInstituto = new List <Instituto>();
            Instituto        instituto     = new Instituto();
            string           respOrgao     = string.Empty;

            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var endereco = Settings.EnderecoApi;
                client.BaseAddress = new Uri(endereco);
                var url         = "instituicao/obter-instituicoes";
                var resultOrgao = await client.GetAsync(url);

                if (!resultOrgao.IsSuccessStatusCode)
                {
                    throw new Exception(resultOrgao.RequestMessage.Content.ToString());
                }

                respOrgao = await resultOrgao.Content.ReadAsStringAsync();


                _Institutos = JsonConvert.DeserializeObject <InstitutoApi>(respOrgao);

                foreach (var obj in _Institutos.data)
                {
                    listInstituto.Add(new Instituto()
                    {
                        Id                = obj.Id,
                        CidadeId          = obj.CidadeId,
                        TipoInstituicaoId = obj.TipoInstituicaoId,
                        NomeInstituto     = obj.nome
                    });
                }
                service.InserirInstituto(listInstituto);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro", ex.Message, "OK");
            }
        }
Ejemplo n.º 2
0
        public async void Institutos(string token)
        {
            InstitutoApi     _Institutos   = new InstitutoApi();
            InstitutoService service       = new InstitutoService();
            List <Instituto> listInstituto = new List <Instituto>();
            Instituto        instituto     = new Instituto();
            string           respOrgao     = string.Empty;

            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                client.BaseAddress = new Uri("http://milenio-app.tst.sistemas.intranet.mpba.mp.br/api/");
                var url         = "instituicao/obter-instituicoes";
                var resultOrgao = await client.GetAsync(url);

                if (!resultOrgao.IsSuccessStatusCode)
                {
                    throw new Exception(resultOrgao.RequestMessage.Content.ToString());
                }

                respOrgao = await resultOrgao.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro", ex.Message, "Ok");
            }
            _Institutos = JsonConvert.DeserializeObject <InstitutoApi>(respOrgao);
            for (int i = 0; i < _Institutos.data.Count; i++)
            {
                instituto.Id                = _Institutos.data[i].Id;
                instituto.CidadeId          = _Institutos.data[i].CidadeId;
                instituto.TipoInstituicaoId = _Institutos.data[i].TipoInstituicaoId;
                instituto.NomeInstituto     = _Institutos.data[i].nome;
                listInstituto.Add(instituto);
            }
            service.InserirInstituto(listInstituto);
        }