Exemplo n.º 1
0
        public async Task <HttpResponseMessage> SendAVG(string url, AverageModelDTO model)
        {
            using HttpClient client = new HttpClient();
            var jsonContent   = JsonConvert.SerializeObject(model);
            var contentString = new StringContent(jsonContent, Encoding.UTF8, "application/json");

            contentString.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            return(await client.PostAsync(url, contentString));
        }
Exemplo n.º 2
0
        public static AverageModelDTO Average(List <AverageCSV> model_csv)
        {
            AverageModelDTO model = new AverageModelDTO();

            model.Averages =
                (from people in model_csv
                 group people by people.City into peopleGroup
                 select new AverageDTO
            {
                City = peopleGroup.Key,
                Age = decimal.Round(peopleGroup.Average(x => x.Age), 2),
            }).ToList();

            return(model);
        }
Exemplo n.º 3
0
        public async Task Run()
        {
            Console.WriteLine(" -- Ler Arquivo --");
            Console.WriteLine("");

            string path = @"..\..\..\input.csv";

            List <AverageCSV> list = FileComponent.ReadCSVFile(path);

            foreach (var item in list)
            {
                Console.WriteLine($"{item.Name} - {item.City} - {item.Age}");
            }

            Console.WriteLine("");
            Console.WriteLine(" -- Media dos dados --");
            Console.WriteLine("");
            AverageModelDTO model = AverageComponent.Average(list);

            foreach (var item in model.Averages)
            {
                Console.WriteLine($"{item.City}, {item.Age}");
            }

            Console.WriteLine("");
            Console.WriteLine(" -- Enviar dados --");
            Console.WriteLine("");

            string url_api  = "https://zeit-endpoint.brmaeji.now.sh/api/avg";
            var    response = await _service.SendAVG(url_api, model);

            if (response.IsSuccessStatusCode)
            {
                var content = response.Content.ReadAsStringAsync();

                Console.WriteLine(content.Result);
            }
        }