Beispiel #1
0
        public async Task <IActionResult> Data(string slug)
        {
            using (var context = new CovidContext())
            {
                District district = await context.Districts
                                    .Where(d => d.Slug == slug)
                                    .Include(d => d.GeoCoordinate)
                                    //.Include(d => d.TimeSeries)
                                    .FirstOrDefaultAsync();


                var query = from dp in context.Set <DataPoint>()
                            where dp.DistrictId == district.Id
                            group dp by dp.SourceFile into s
                            where s.Count() > 0
                            orderby s.Key
                            select new Totals()
                {
                    SourceFile = s.Key,
                    Deaths     = (int)s.Sum(x => x.Deaths),
                    Confirmed  = (int)s.Sum(x => x.Deaths),
                    Recovered  = (int)s.Sum(x => x.Deaths),
                    Active     = (int)s.Sum(x => x.Active),
                    Count      = s.Count()
                };
                district.TimeSeries = await query.ToListAsync();

                return(new OkObjectResult(district));
            }
        }
Beispiel #2
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            using (var context = new CovidContext())
            {
                context.Database.Migrate();
            }

            //builder.AddSwashBuckle(Assembly.GetExecutingAssembly());
            builder.Services.AddDbContext <CovidContext>();
            //builder.Services.AddAddJsonOptions(options =>
            //        {
            //            options.JsonSerializerOptions.IgnoreNullValues = true;
            //        });
            //builder.Services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1",
            //        new OpenApiInfo
            //        {
            //            Title = "CovidApi.Codelifter.IO",
            //            Version = "v1",
            //            Description = @"An easy to use API to track the number sof the growing SARS-CoV-2 novel Coronavirus pandemic.  All unique location endpoints return current data, totals, and timeseries.",
            //            Contact = new OpenApiContact
            //            {
            //                Name = "Andrew Palmer (CodeLifterIO)",
            //                Email = "*****@*****.**"
            //            },
            //            License = new OpenApiLicense
            //            {
            //                Name = "MIT License",
            //                Url = new Uri("https://www.mit.edu/~amini/LICENSE.md")
            //            }
            //        });
            //});
        }
Beispiel #3
0
        public async Task <IActionResult> Data([FromRoute] string slug)
        {
            Country country = null;

            using (var context = new CovidContext())
            {
                country = await context.Countries
                          .Where(c => c.Slug == slug)
                          .Include(c => c.GeoCoordinate)
                          .FirstOrDefaultAsync();


                var query = from dp in context.Set <DataPoint>()
                            where dp.CountryId == country.Id
                            group dp by dp.SourceFile into s
                            where s.Count() > 0
                            orderby s.Key
                            select new Totals()
                {
                    SourceFile = s.Key,
                    Deaths     = (int)s.Sum(x => x.Deaths),
                    Confirmed  = (int)s.Sum(x => x.Deaths),
                    Recovered  = (int)s.Sum(x => x.Deaths),
                    Active     = (int)s.Sum(x => x.Active),
                    Count      = s.Count()
                };
                country.TimeSeries = query.ToList();
                return(new OkObjectResult(country));
            }
        }
Beispiel #4
0
        private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Get the token from the previous step. Note that we could also have gotten the
            // token directly from the prompt itself. There is an example of this in the next method.
            var tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse?.Token != null)
            {
                // Pull in the data from the Microsoft Graph.
                var client = new SimpleGraphClient(tokenResponse.Token);
                var me     = await client.GetMeAsync();

                var title = !string.IsNullOrEmpty(me.JobTitle) ?
                            me.JobTitle : "Unknown";

                string respuesta = $"{me.DisplayName} ({me.UserPrincipalName}) iniciaste sesión correctamente.";

                var _context = new CovidContext();
                var comuna   = (await _context.EstadoComunas.Include(e => e.IdComunaNavigation).Include(e => e.IdFaseNavigation).Where(e => e.IdComunaNavigation.StrDescripcion.Contains($"{me.City}")).ToListAsync()).FirstOrDefault();
                if (comuna != null)
                {
                    respuesta += $" Tu comuna {comuna.IdComunaNavigation.StrDescripcion} está en fase {comuna.IdFaseNavigation.Nombre}";
                }
                await stepContext.Context.SendActivityAsync(respuesta);



                return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to view your token?") }, cancellationToken));
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken);

            return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
        }
Beispiel #5
0
        public IActionResult Criar(string pais, string casos, string mortes, string recuperados)
        {
            using (var db = new CovidContext())
            {
                // Se existir o país:
                if (db.Infeccoes.Where(infeccao => infeccao.Pais.Nome == pais).Any())
                {
                    var inf = db.Infeccoes.Where(infeccao => infeccao.Pais.Nome == pais).First();
                    inf.CasosConfirmados = int.Parse(casos);
                    inf.Mortes           = int.Parse(mortes);
                    inf.Recuperados      = int.Parse(recuperados);
                    db.Update(inf);
                }
                else
                {
                    var novopais = new PaisModel();
                    novopais.Nome = pais;
                    var novainfection = new InfeccaoModel();
                    novainfection.CasosConfirmados = int.Parse(casos);
                    novainfection.Mortes           = int.Parse(mortes);
                    novainfection.Recuperados      = int.Parse(recuperados);

                    novopais.Infeccao = novainfection;
                    db.Infeccoes.Add(novainfection);
                    db.Paises.Add(novopais);
                }
                db.SaveChanges();

                var infeccoes = db.Infeccoes.ToList();
                db.Paises.ToList();
                ViewData["Infeccoes"] = infeccoes;
                return(View("Painel"));
            }
        }
Beispiel #6
0
 public EchoBot(CovidContext covidContext, ConversationState conversationState, UserState userState, T dialog, ILogger <EchoBot <T> > logger)
 {
     _context          = covidContext;
     ConversationState = conversationState;
     UserState         = userState;
     Dialog            = dialog;
     Logger            = logger;
 }
Beispiel #7
0
 public UnitOfWork(CovidContext context)
 {
     _context       = context;
     Citizens       = new CitizenRepository(_context);
     Municipalities = new MunicipalityRepository(_context);
     //Courses = new CourseRepository(_context);
     //Authors = new AuthorRepository(_context);
 }
Beispiel #8
0
 public static void GenerateDatabaseBackup()
 {
     using (var context = new CovidContext())
     {
         int result = context.Database.ExecuteSqlRaw("EXEC SP_Backup_Database;");
         //context.StoredProcedures.FromSqlRaw("EXEC SP_Backup_Database;").FirstOrDefaultAsync();
     }
 }
Beispiel #9
0
 public static void SummarizeDistricts()
 {
     using (var context = new CovidContext())
     {
         int result = context.Database.ExecuteSqlRaw($"EXEC SP_Update_Summary_On_District;");
         //context.StoredProcedures.FromSqlRaw("EXEC SP_Update_Summary_On_District;").FirstOrDefaultAsync();
     }
 }
Beispiel #10
0
 public static Country Find(Country entity)
 {
     using (var context = new CovidContext())
     {
         return(context.Countries
                .Where(c => c.Name == entity.Name || c.Slug == entity.Slug)
                .FirstOrDefault());
     }
 }
Beispiel #11
0
 public static District Find(District entity)
 {
     using (var context = new CovidContext())
     {
         return(context.Districts
                .Where(p => p.Name == entity.Name || p.Slug == entity.Slug)
                .FirstOrDefault());
     }
 }
Beispiel #12
0
        public async Task <IActionResult> Countries()
        {
            using (var context = new CovidContext())
            {
                List <Country> countries = await context.Countries
                                           .Include(country => country.GeoCoordinate)
                                           .ToListAsync();

                return(new OkObjectResult(countries));
            }
        }
        public IActionResult Index()
        {
            using (var db = new CovidContext())
            {
                var infeccoes = db.Infeccoes.ToList();
                db.Paises.ToList();

                ViewData["Infeccoes"] = infeccoes;
                return(View());
            }
        }
Beispiel #14
0
        public static Province Find(Province entity)
        {
            using (var context = new CovidContext())
            {
                // Province province = context.Provinces.Find(entity);
                // if(null != province) return province;

                return(context.Provinces
                       .Where(p => p.Name == entity.Name || p.Slug == entity.Slug)
                       .FirstOrDefault());
            }
        }
Beispiel #15
0
 public UnitOfWork(CovidContext context)
 {
     _context              = context;
     Citizens              = new CitizenRepository(_context);
     Municipalities        = new MunicipalityRepository(_context);
     TestCenters           = new TestCenterRepository(_context);
     TestCenterManagements = new TestCenterManagementRepository(_context);
     TestDates             = new TestDateRepository(_context);
     Locations             = new LocationRepository(_context);
     //Courses = new CourseRepository(_context);
     //Authors = new AuthorRepository(_context);
 }
Beispiel #16
0
 public UnitOfWork(CovidContext context, ApplicationUserManager userManager,
                   ICompaniesRepository companiesRepository, IBranchesRepository branchesRepository, IReviewsRepository reviewsRepository,
                   INewsArticlesRepository newsArticlesRepository, IReportsRepository reportsRepository, IRefreshTokensRepository refreshTokensRepository)
 {
     _context      = context;
     UserManager   = userManager;
     Companies     = companiesRepository;
     Branches      = branchesRepository;
     Reviews       = reviewsRepository;
     NewsArticles  = newsArticlesRepository;
     Reports       = reportsRepository;
     RefreshTokens = refreshTokensRepository;
 }
Beispiel #17
0
        public static GeoCoordinate Find(GeoCoordinate entity)
        {
            if (0 != entity.Id)
            {
                return(entity);
            }

            using (var context = new CovidContext())
            {
                return(context.GeoCoordinates
                       .Where(g => g.Latitude == entity.Latitude && g.Longitude == entity.Longitude)
                       .FirstOrDefault());
            }
        }
Beispiel #18
0
        public static void Update(Entity entity)
        {
            if (entity.Id == 0)
            {
                Insert(entity);
                return;
            }

            using (var context = new CovidContext())
            {
                context.Update(entity);
                context.SaveChanges();
            }
        }
Beispiel #19
0
        public async Task <IActionResult> Provinces([FromRoute] string slug, [FromQuery] string searchTerm = "")
        {
            Country country = null;

            using (var context = new CovidContext())
            {
                country = await context.Countries
                          .Where(c => c.Slug == slug)
                          .Include(c => c.GeoCoordinate)
                          .FirstOrDefaultAsync();

                var query = from dp in context.Set <DataPoint>()
                            where dp.CountryId == country.Id
                            group dp by dp.SourceFile into s
                            where s.Count() > 0
                            orderby s.Key
                            select new Totals()
                {
                    SourceFile = s.Key,
                    Deaths     = (int)s.Sum(x => x.Deaths),
                    Confirmed  = (int)s.Sum(x => x.Deaths),
                    Recovered  = (int)s.Sum(x => x.Deaths),
                    Active     = (int)s.Sum(x => x.Active),
                    Count      = s.Count()
                };
            }

            List <Province> provinces = null;

            if (null != country)
            {
                using (var context = new CovidContext())
                {
                    var query = context.Provinces
                                .Where(p => p.CountryId == country.Id);

                    if (!string.IsNullOrWhiteSpace(searchTerm))
                    {
                        query = query.Where(p => p.Name.Contains(searchTerm) || p.Slug.Contains(searchTerm));
                    }

                    provinces = await query.Include(p => p.Country)
                                .Include(p => p.GeoCoordinate)
                                .ToListAsync();
                }
            }

            return(new OkObjectResult(provinces));
        }
Beispiel #20
0
        public async Task <IActionResult> Province([FromRoute] string slug)
        {
            using (var context = new CovidContext())
            {
                Province province = await context.Provinces
                                    .Where(p => p.Slug == slug)
                                    .Include(p => p.Country)
                                    .Include(p => p.GeoCoordinate)
                                    .FirstOrDefaultAsync();

                province.TimeSeries = await GetTimeSeriesStatistics(context.DataPoints, province);

                return(new OkObjectResult(province));
            }
        }
Beispiel #21
0
        public IActionResult Remover(string infeccaoId)
        {
            using (var db = new CovidContext())
            {
                db.Infeccoes.Remove(db.Infeccoes.Where(i => i.InfeccaoId == int.Parse(infeccaoId)).First());

                db.SaveChanges();

                var infeccoes = db.Infeccoes.ToList();
                db.Paises.ToList();

                ViewData["Infeccoes"] = infeccoes;
                return(View("Painel"));
            }
        }
Beispiel #22
0
        public async Task DownloadAllFiles(string startFile = null)
        {
            TwilioService twilioService = new TwilioService();

            bool isStarted = false;

            string lastFile = "";
            using (var context = new CovidContext())
            {
                List<DataCollectionStatistic> startFileStat = await context.DataCollectionStatistics.ToListAsync();
                lastFile = startFileStat?.Last()?.FileName;
            }

            if (string.IsNullOrWhiteSpace(startFile) && string.IsNullOrWhiteSpace(lastFile))
            {
                isStarted = true;
            }

            List<DataFile> files = new List<DataFile>();

            files = await GetListOfFiles("CSSEGISandData",
                                                "COVID-19",
                                                "csse_covid_19_data/csse_covid_19_daily_reports");
            foreach (DataFile file in files)
            {
                if (file.FileName == startFile)
                {
                    isStarted = true;
                }

                if (isStarted == true)
                {
                    DateTime startTime = DateTime.Now;
                    await ParseAndDeleteFile(file);
                    await SaveEntriesToDataModel(file.FileName);
                    DateTime fileComplete = DateTime.Now;
                    var elapsed = fileComplete - startTime;
                    twilioService.SendSMS($"COVIDAP -> File {file.FileName}. Records:{Entries.Count} Completed in {elapsed.Minutes}:{elapsed.Seconds}");
                    Entries.Clear();
                }

                if (file.FileName == lastFile)
                {
                    isStarted = true;
                }
            }
            twilioService.SendSMS("COVIDAP -> SUCCESS - UP TO DATE");
        }
Beispiel #23
0
        public static DataPoint Find(DataPoint entity)
        {
            if (0 != entity.Id)
            {
                return(entity);
            }

            using (var context = new CovidContext())
            {
                return(context.DataPoints
                       .Where(dp => dp.LastUpdate == entity.LastUpdate &&
                              dp.CountryId == entity.CountryId &&
                              dp.ProvinceId == entity.ProvinceId &&
                              dp.DistrictId == entity.DistrictId)
                       .FirstOrDefault());
            }
        }
Beispiel #24
0
        public IActionResult Index(string senha)
        {
            if (senha == Senha)
            {
                using (var db = new CovidContext())
                {
                    var infeccoes = db.Infeccoes.ToList();
                    db.Paises.ToList();

                    ViewData["Infeccoes"] = infeccoes;

                    return(View("Painel"));
                }
            }
            else
            {
                ViewData["SenhaInvalida"] = true;
                return(View());
            }
        }
Beispiel #25
0
        public async Task <IActionResult> Global()
        {
            using (var context = new CovidContext())
            {
                Planet earth   = new Planet();
                var    tsQuery = from dp in context.Set <DataPoint>()
                                 group dp by dp.SourceFile into s
                                 where s.Count() > 0
                                 orderby s.Key
                                 select new Totals()
                {
                    SourceFile = s.Key,
                    Deaths     = (int)s.Sum(x => x.Deaths),
                    Confirmed  = (int)s.Sum(x => x.Deaths),
                    Recovered  = (int)s.Sum(x => x.Deaths),
                    Active     = (int)s.Sum(x => x.Active),
                    Count      = s.Count()
                };
                earth.TimeSeries = await tsQuery.ToListAsync();

                earth.CurrentData = earth.TimeSeries.Last();
                return(new OkObjectResult(earth));
            }
        }
Beispiel #26
0
        public async Task <IActionResult> Districts([FromRoute] string slug, [FromQuery] string searchTerm = "")
        {
            Province province;

            using (var context = new CovidContext())
            {
                province = await context.Provinces
                           .Where(p => p.Slug == slug)
                           .Include(p => p.GeoCoordinate)
                           .Include(p => p.Country)
                           .FirstOrDefaultAsync();
            }

            List <District> districts = null;

            if (null != province)
            {
                using (var context = new CovidContext())
                {
                    var query = context.Districts
                                .Where(p => p.ProvinceId == province.Id);

                    if (!string.IsNullOrWhiteSpace(searchTerm))
                    {
                        query = query.Where(d => d.Name.Contains(searchTerm) || d.Slug.Contains(searchTerm));
                    }

                    districts = await query.Include(p => p.Country)
                                .Include(p => p.Province)
                                .Include(p => p.GeoCoordinate)
                                .ToListAsync();
                }
            }

            return(new OkObjectResult(districts));
        }
Beispiel #27
0
 public TotalGeralUfRepository(CovidContext context) : base(context)
 {
 }
 public CitizenRepository(CovidContext context) : base(context)
 {
 }
Beispiel #29
0
 public CompaniesRepository(CovidContext context) : base(context)
 {
 }
Beispiel #30
0
 public CasoRepository(CovidContext context) : base(context)
 {
 }