Beispiel #1
0
        public IActionResult Index()
        {
            var all = new allDTO();

            all = Infrastructure.Heraku.GetAllDTOFromHeraku("");

            if (all == null)
            {
                return(View());
            }

            return(View(all));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            var all = new allDTO();

            all = Infrastructure.Heraku.GetAllDTOFromHeraku("");

            if (all != null)
            {
                return(View(nameof(Index), all));
            }

            return(View());
        }
Beispiel #3
0
        public async Task <ActionResult <All> > PostAll()
        {
            allDTO allDTO = new allDTO();

            allDTO = covid_19.Infrastructure.Heraku.GetAllDTOFromHeraku("");

            All all = new All(allDTO);

            if (all != null)
            {
                _context.All.Add(all);
            }
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAll", new { id = all.Id }, all));
        }
Beispiel #4
0
        public static allDTO GetAllDTOFromHeraku(string BaseAddress)
        {
            All all = new All();
            //Martin: this will overuse the server's resources
            HttpClient client = new HttpClient();

            //HTTP GET
            if (BaseAddress == "")
            {
                client.BaseAddress = new Uri("https://coronavirus-19-api.herokuapp.com/");
            }

            var responseTask = client.GetAsync("all");

            try
            {
                responseTask.Wait();

                var content = responseTask.Result.Content.ReadAsStringAsync().Result;

                if (responseTask.Result.IsSuccessStatusCode)
                {
                    allDTO alls = JsonConvert.DeserializeObject <allDTO>(content);

                    return(alls);
                }
                else //web api sent error response
                {
                    //log response status here..
                    throw new NotImplementedException();
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Error reading from {0}. Message = {1}", e.TargetSite.Name.ToString(), e.Message);
                return(null);
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Save(int cases, int deaths, int recovered, DateTime timestamp)
        {
            var allDTO = new allDTO();

            allDTO.cases     = cases;
            allDTO.deaths    = deaths;
            allDTO.recovered = recovered;

            //all = Infrastructure.Heraku.GetAllDTOFromHeraku("");

            if (allDTO != null)
            {
                var all = new All(allDTO);
                all.Date = timestamp;

                _context.Add(all);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "AllMVC"));
                //return View(nameof(Index), allDTO);
            }

            return(View());
        }
Beispiel #6
0
        private All GetAllFromHeraku(string BaseAddress)
        {
            All all = new All();
            //Martin: this will overuse the server's resources
            HttpClient client = new HttpClient();

            //HTTP GET
            if (BaseAddress == "")
            {
                client.BaseAddress = new Uri("https://coronavirus-19-api.herokuapp.com/");
            }

            var responseTask = client.GetAsync("all");

            responseTask.Wait();


            var content = responseTask.Result.Content.ReadAsStringAsync().Result;

            if (responseTask.Result.IsSuccessStatusCode)
            {
                allDTO alls = JsonConvert.DeserializeObject <allDTO>(content);

                all.Cases     = alls.cases;
                all.Deaths    = alls.deaths;
                all.Recovered = alls.recovered;
                all.Date      = DateTime.Now;

                return(all);
            }
            else //web api sent error response
            {
                //log response status here..
                return(all);
            }
        }