Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
0
 protected Repository(CovidContext context)
 {
     Db    = context;
     DbSet = Db.Set <TEntity>();
 }