Exemplo n.º 1
0
        public IEnumerable <CovidObservationDatum> GetTopConfirmed(
            CovidDashboardResourceParameters resourceParameters)
        {
            var numberOfItemsToDisplay = resourceParameters?.Max_Results ?? null;
            var observationDate        = resourceParameters.Observation_Date ?? null;

            if (numberOfItemsToDisplay == null && observationDate == null)
            {
                return(GetTopConfirmed());
            }

            var collection = _context.CovidObservationData as IEnumerable <CovidObservationDatum>;

            if (observationDate != null)
            {
                collection = collection.Where(x => x.ObservationDate == observationDate)
                             .GroupBy(x => x.Country)
                             .Select(group =>
                                     new CovidObservationDatum
                {
                    Country   = group.Key,
                    Confirmed = group.Sum(x => x.Confirmed),
                    Recovered = group.Sum(x => x.Recovered),
                    Deaths    = group.Sum(x => x.Deaths)
                })
                             .OrderByDescending(group => group.Confirmed);
            }

            if (numberOfItemsToDisplay != null)
            {
                collection = collection.Take(numberOfItemsToDisplay.Value);
            }

            return(collection.ToList());
        }
Exemplo n.º 2
0
        public ActionResult <IEnumerable <CovidObservationDatumDto> > GetTopConfirmed(
            [FromQuery()] CovidDashboardResourceParameters resourceParameters)
        {
            var results           = _dashBoardRepository.GetTopConfirmed(resourceParameters);
            var covidCaseDataList = _covidCaseDataMapper.ToCovidCaseDataListDto(results);

            return(Ok(covidCaseDataList));
        }