コード例 #1
0
        public async Task ObterTodos()
        {
            try
            {
                _logger.LogInformation("**** Obter todos iniciado ****");

                var response = await _httpClient.GetAsync("https://jsonplaceholder.typicode.com/todos");

                if (!await ValidarResposta(response))
                {
                    return;
                }

                var todos = await DeserializarRespostaAsync <IEnumerable <Todo> >(response);

                foreach (var todo in todos)
                {
                    await _todoRepository.Adicionar(todo);
                }

                _logger.LogInformation("**** Todos incluidos com sucesso ****");
            }
            catch (Exception e)
            {
                _logger.LogError(@$ "**** Falha ao executar job ****\nDetalhes: {e.Message}\n");
            }
        }