Пример #1
0
        public async Task <Result <Covid19> > AddCovidAsync(Covid19 covid)
        {
            var result = new Result <Covid19>();

            try
            {
                var Covid19 = new Covid19
                {
                    Id          = Guid.NewGuid().ToString(),
                    Confirmados = covid.Confirmados,
                    DadosDoDia  = covid.DadosDoDia,
                    Local       = covid.Local,
                    Mortes      = covid.Mortes,
                    Recuperados = covid.Recuperados,
                };

                var save = await this.AddAsync(Covid19);

                return(save > 0 ? result.ResultResponse(
                           this.ListAsync().GetAwaiter().GetResult().First(x => x.Id == Covid19.Id))
                    : throw new Exception());
            }
            catch (Exception exc)
            {
                return(result.ResultError(exc.Message));
            }
        }
Пример #2
0
        public async Task <List <Covid19> > GetCovid19CasesAsync()
        {
            var    listResult = new List <Covid19>();
            string url        = $"https://news.google.com/covid19/map?hl=pt-BR&gl=BR&ceid=BR:pt-419";
            var    html       = await WebScrapingCore(url).ConfigureAwait(false);

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(html);

            foreach (var row in htmlDocument.DocumentNode.SelectNodes("//*[@class='pH8O4c']//tr"))
            {
                string local   = null;
                var    nodesTh = row.SelectNodes("th");
                if (nodesTh != null)
                {
                    local = nodesTh[0].InnerText;
                }
                var nodes = row.SelectNodes("td");
                if (nodes != null)
                {
                    var coronaData = new Covid19();
                    coronaData.Id          = Guid.NewGuid().ToString();
                    coronaData.Local       = local;
                    coronaData.Confirmados = nodes[0].InnerText;
                    coronaData.Mortes      = nodes[4].InnerText;
                    coronaData.Recuperados = nodes[3].InnerText;
                    coronaData.DadosDoDia  = DateTime.Now.ToString(dateFormat);
                    listResult.Add(coronaData);
                }
            }

            return(listResult);
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UkupanBrRegSlucajeva,BrojSmrtnihSlucajeva,ProcenatSmrtnosti,BrojTestiranihOsoba,BrojTestiranihOsoba24h,BrojPotvrdjenihSlucajeva24h,BrojPreminulihosoba24h,BrojAktivnihSlucajeva,BrojOsobaNaRespiratorima")] Covid19 covid19)
        {
            if (id != covid19.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(covid19);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Covid19Exists(covid19.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(covid19));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,UkupanBrRegSlucajeva,BrojSmrtnihSlucajeva,ProcenatSmrtnosti,BrojTestiranihOsoba,BrojTestiranihOsoba24h,BrojPotvrdjenihSlucajeva24h,BrojPreminulihosoba24h,BrojAktivnihSlucajeva,BrojOsobaNaRespiratorima")] Covid19 covid19)
        {
            if (ModelState.IsValid)
            {
                _context.Add(covid19);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(covid19));
        }
        public void Get_Covid_Data_Test()
        {
            var covidObj = new Covid19();

            var local_Filter = "Brasil";

            var sortinfFiled = GetPropertyName(
                () => covidObj.Confirmados);

            var total = _ICovidLogic.GetDbReportFromCountry(local_Filter, sortinfFiled);

            Assert.NotEmpty(total);
            Assert.NotNull(total);
        }
Пример #6
0
        private void SearchClick(object sender, RoutedEventArgs e)
        {
            string country = TextBoxCountry.Text;
            string region  = TextBoxRegion.Text;

            string dateFrom = DatesRange.SelectedDates[0].ToString("yyyy-MM-dd");

            string dateTo = DatesRange.SelectedDates[DatesRange.SelectedDates.Count - 1].ToString("yyyy-MM-dd");

            var covidMyRS = Covid19.doCovidProcess(country, region, dateFrom, dateTo);

            var result = Covid19.buildStringTelegram(covidMyRS);

            TextBoxResult.Text = result;
        }
Пример #7
0
        /// <summary>
        /// list with latest numbers from DB
        /// </summary>
        /// <param name="localFilter"></param>
        /// <param name="sortingField"></param>
        /// <returns></returns>
        public List <Covid19> GetDataFromMongoDB(string country, string sortingByField)
        {
            var coronaObj      = new Covid19();
            var listCoronaData = new List <Covid19>();

            //configure filtering
            var filter = Builders <Covid19> .Filter.Or(
                Builders <Covid19> .Filter.Where(p => p.Local.ToLower().Contains(country.ToLower())));

            //configure sorting
            var sort = Builders <Covid19> .Sort.Descending(sortingByField);

            listCoronaData = _iMongoGeneric.GetdbCollectionGeneric(coronaObj, "node", filter, sort);

            return(listCoronaData);
        }
Пример #8
0
        private void SaveClick(object sender, RoutedEventArgs e)
        {
            string country = TextBoxCountry.Text;
            string region  = TextBoxRegion.Text;

            string dateFrom = DatesRange.SelectedDates[0].ToString("yyyy-MM-dd");

            string dateTo = DatesRange.SelectedDates[DatesRange.SelectedDates.Count - 1].ToString("yyyy-MM-dd");

            var covidMyRS = Covid19.doCovidProcess(country, region, dateFrom, dateTo);

            string covidCSV = Covid19.buildStringCSV(covidMyRS);

            File.WriteAllText("covidTable.csv", covidCSV, Encoding.UTF8);

            TextBoxResult.Text = "El archivo se ha guardado";
        }
Пример #9
0
        public IActionResult InitializeCovid()
        {
            Random rnd = new Random();

            Enumerable.Range(1, 10).ToList().ForEach(x =>
            {
                foreach (ECity item in Enum.GetValues(typeof(ECity)))
                {
                    var newcovid = new Covid19 {
                        City = item, Count = rnd.Next(100, 1000), CovidDate = DateTime.Now.AddDays(x)
                    };
                    _covidService.SaveCovidData(newcovid).Wait();
                    System.Threading.Thread.Sleep(1000);
                }
            });

            return(Ok("Covid data was inserted Db"));
        }
        public void CanChangeCovid19Data()
        {
            // Arrange
            var p = new Covid19 {
                infected = 20000, dead = 1000, recovered = 10000, deadPt = 2.5, recPt = 10.4
            };

            // Act
            p.infected  = 10000;
            p.dead      = 3004;
            p.recovered = 13333;
            p.deadPt    = 23.5;
            p.recPt     = 64.6;
            //Assert
            Assert.Equal(10000, p.infected);
            Assert.Equal(3004, p.dead);
            Assert.Equal(13333, p.recovered);
            Assert.Equal(23.5, p.deadPt);
            Assert.Equal(64.6, p.recPt);
        }
Пример #11
0
        private void btnEjecutar_Click(object sender, EventArgs e)
        {
            Microorganismo nuevo;

            switch (this.cmbMicroorganismo.SelectedIndex)
            {
            case 0:
                nuevo = new Covid19("Cepa Argentina");
                GrupoDePrueba <Covid19> .InfectarPoblacion(nuevo);

                Ejecutar <Microorganismo>(nuevo);
                break;

            case 1:
                nuevo = new Gripe("Gripe Meli", ETipo.Virus, EContagiosidad.Alta);
                GrupoDePrueba <Gripe> .InfectarPoblacion(nuevo);

                Ejecutar <Microorganismo>(nuevo);
                break;
            }
        }
Пример #12
0
        /// <summary>
        /// update Covid19
        /// </summary>
        /// <param name="id"></param>
        /// <param name="Covid19"></param>
        /// <returns></returns>
        public async Task <Result <Covid19> > UpdateAsync(Guid id, Covid19 Covid19)
        {
            var result = new Result <Covid19>();

            var resource = await this.GetEntityAsync(id);

            if (resource == null)
            {
                return(result.ResultError("Resource not found!"));
            }

            //use reflection to check wich properties have changed and set proper value
            foreach (var entityProp in Covid19.GetType().GetProperties())
            {
                var entityValue = entityProp.GetValue(Covid19);

                if (entityProp.Name != "Id" && (!string.IsNullOrEmpty(entityValue as string) || entityValue != null))
                {
                    foreach (var resourceProp in resource.GetType().GetProperties().Where(x => x.Name == entityProp.Name))
                    {
                        var resourceValue = resourceProp.GetValue(resource);

                        if (string.IsNullOrEmpty(resourceValue as string) && entityValue != null || !resourceValue.ToString().ToLower().Equals(entityValue.ToString().ToLower()))
                        {
                            resourceProp.SetValue(resource, entityValue, null);
                        }
                    }
                }
            }


            if (await this.UpdateAsync(resource) <= 0)
            {
                return(result.ResultError("The resource was not updated!"));
            }
            else
            {
                return(result.ResultResponse(resource));
            }
        }
Пример #13
0
        public async Task <List <Covid19> > GetDataFromMongoDbByDateAsync(string date = null)
        {
            var coronaData = new Covid19();

            //filter date today
            if (string.IsNullOrEmpty(date))
            {
                date = DateTime.Now.ToString(dateOnlyFormat);
            }

            //configure filtering
            var filter_date = Builders <Covid19> .Filter.Or(
                Builders <Covid19> .Filter.Where(p => p.DadosDoDia.ToLower().Contains(date.ToLower()))
                );

            //configure sorting
            var sort = Builders <Covid19> .Sort.Descending("Confirmados");

            //get data
            var result_local = await Task.Run(() => GetDataFromMongoDB(coronaData, "node", filter_date, sort));

            return(result_local);
        }
Пример #14
0
        public string GetDbReportFromCountry(string country, string sortingByField)
        {
            var coronaData = new Covid19();
            var result     = string.Empty;

            //configure filtering
            var filter = Builders <Covid19> .Filter.Or(
                Builders <Covid19> .Filter
                .Where(p => p.Local.ToLower().Contains(country.ToLower())
                       ));

            //configure sorting
            var sort = Builders <Covid19> .Sort.Descending(sortingByField);

            //

            var result_local = _iMongoGeneric.GetdbCollectionGeneric(coronaData, "node", filter, sort);

            if (result_local.Any())
            {
                //use reflection to get data accordingly to sortingField
                foreach (var entityProp in result_local[0].GetType().GetProperties())
                {
                    if (entityProp.Name == sortingByField)
                    {
                        var entityValue = entityProp.GetValue(result_local[0]);
                        if (!string.IsNullOrEmpty(entityValue as string))
                        {
                            result = entityValue.ToString();
                        }
                    }
                }
            }

            return(result);
        }
Пример #15
0
 public async Task <int> UpdateAsync(Covid19 Covid19)
 {
     return(await this._ICovid19.UpdateAsync(Covid19));
 }
Пример #16
0
 public ViewResult Index()
 {
     return(View("Index", Covid19.Get()));
 }
Пример #17
0
 public async Task <int> AddAsync(Covid19 Covid19)
 {
     return(await this._ICovid19.AddAsync(Covid19));
 }
Пример #18
0
        /// <summary>
        /// get Covid19
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Covid19> GetEntityAsync(Guid id)
        {
            Covid19 Covid19 = await _ICovid19.GetEntityAsync(id);

            return(Covid19);
        }
Пример #19
0
 public async Task <int> DeleteAsync(Covid19 Covid19)
 {
     return(await this._ICovid19.DeleteAsync(Covid19));
 }
Пример #20
0
        public async Task <IActionResult> SaveCovid(Covid19 covid)
        {
            await _covidService.SaveCovidData(covid);

            return(Ok(_covidService.GetCovidChartList()));
        }