Пример #1
0
        public async Task <ActionResult <IEnumerable <UserDadosDto> > > GetAll()
        {
            try
            {
                var myUsername = User.Identity.Name;
                if (ZZApiMain.VerifyUserAuthorize(myUsername))
                {
                    if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn))
                    {
                        var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.GetAll, Tela = Tela });

                        var responseCommand = await myConn.Zz.GetApiWaitCommand(myId);

                        if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk))
                        {
                            return(await SerializerAsync.DeserializeJsonList <UserDadosDto>(responseCommand.Json));
                        }
                    }
                }
                return(NotFound());
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(NotFound());
            }
        }
Пример #2
0
        private static async Task <List <Estado> > SearchEstadoAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(EstadosUrl);
                var response = await client.GetAsync($"", CancellationToken.None);

                response.EnsureSuccessStatusCode();
                var jsonContent = await response.Content.ReadAsStringAsync();

                var jsonList = await SerializerAsync.DeserializeJsonList <EstadoIbge>(jsonContent);

                var estadoList = new List <Estado>();
                foreach (var ibge in jsonList)
                {
                    estadoList.Add(new Estado
                    {
                        Ibge = ibge.Id, Descricao = ibge.Nome, Sigla = ibge.Sigla, IsActive = true, Codigo = ibge.Sigla
                    });
                }

                return(estadoList);
            }
        }
Пример #3
0
        /// <summary>
        /// Searches the asynchronous.
        /// </summary>
        /// <param name="stateInitials">The state initials.</param>
        /// <param name="city">The city.</param>
        /// <param name="address">The address.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public static async Task <IEnumerable <ViaCEPResult> > SearchAddressAsync(
            String stateInitials,
            String city,
            String address,
            CancellationToken token)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseUrl);
                var response = await client.GetAsync($"/ws/{stateInitials}/{city}/{address}/json", token).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
                var jsonContent = await response.Content.ReadAsStringAsync();

                var jsonList = await SerializerAsync.DeserializeJsonList <ViaCEPResult>(jsonContent);

                foreach (var json in jsonList)
                {
                    json.ZipCode = new String(json.ZipCode.Where(Char.IsDigit).ToArray());
                }

                return(jsonList);
            }
        }
Пример #4
0
        private static async Task <List <Cidade> > SearchMunicipioAsync(int uf, long ufId)
        {
            using (var client = new HttpClient())
            {
                var url      = EstadosUrl + "/" + uf + "/municipios";
                var response = await client.GetAsync(url, CancellationToken.None).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
                var jsonContent = await response.Content.ReadAsStringAsync();

                var jsonList = await SerializerAsync.DeserializeJsonList <CidadeIbge>(jsonContent);

                var cidades = new List <Cidade>();
                foreach (var ibge in jsonList)
                {
                    cidades.Add(new Cidade
                    {
                        Ibge = ibge.Id, Descricao = ibge.Nome, EstadoId = ufId, IsActive = true, Codigo = ibge.Id.ToString()
                    });
                }

                return(cidades);
            }
        }