Пример #1
0
        public async Task <IActionResult> GetAllWeatherForecasts([FromQuery] string jsonFilterDefinition = null, [FromQuery] string jsonSortingDefinition = null, [FromQuery] int?page = null, [FromQuery] int?pageSize = null)
        {
            if (!page.HasValue)
            {
                page = 1;
            }

            if (!pageSize.HasValue)
            {
                pageSize = 10;
            }

            var allItemCount = await _weatherRepository.Count(jsonFilterDefinition : jsonFilterDefinition);

            var paginationMetadata = new
            {
                totalCount  = allItemCount,
                pageSize    = pageSize,
                currentPage = page,
                totalPages  = (int)Math.Ceiling(allItemCount / (double)pageSize)
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationMetadata));


            return(Ok(await _weatherRepository.GetAll(jsonFilterDefinition: jsonFilterDefinition, jsonSortingDefinition: jsonSortingDefinition, page: page, pageSize: pageSize)));
        }
        public void ProceedCity(IForecastService service, City city)
        {
            var result    = service.ForecastData(city.Name);
            var serviceId = _identifier.IdentifierFor(service.GetType());

            if (!result.Success)
            {
                return;
            }
            var data = _forecastRepository
                       .GetAll()
                       .Where(x => x.City.Id == city.Id && x.Service.Id == serviceId);

            foreach (var item in data)
            {
                _forecastRepository.Delete(item.Id);
            }
            foreach (var dto in result.Items)
            {
                _forecastRepository.Insert(new WeatherForecast
                {
                    City           = city,
                    Date           = dto.Date,
                    Humidity       = dto.Humidity,
                    DayTemperature = dto.MaxTemperature,
                    Service        = new ForecastServiceEntity {
                        Id = serviceId
                    }
                });
            }
        }
        public async Task <IEnumerable <WeatherForecast> > GetAll()
        {
            var result = new List <WeatherForecast>();

            await foreach (var dataPoint in _weatherForecastRepository.GetAll())
            {
                result.Add(dataPoint);
            }

            return(result);
        }
Пример #4
0
        public List <WeatherForecastModel> GetAllWetherForecasts()
        {
            List <WeatherForecastModel> result = new List <WeatherForecastModel>();

            foreach (var x in repository.GetAll())
            {
                result.Add(new WeatherForecastModel {
                    Date = x.Date, Summary = x.Summary, TemperatureC = x.TemperatureC
                });
            }
            return(result);
        }
Пример #5
0
        public virtual IList <AvgForecastDto> GetAverageDataForOneCity(int cityId)
        {
            var numberGroups =
                from n in _forecastRepository.GetAll().Where(c => c.City.Id == cityId)
                group n by n.Date into g
                select new AvgForecastDto
            {
                Date           = g.Key,
                AvgTemperature = (int)g.Average(x => x.DayTemperature),
                AvgHumidity    = (int)g.Average(x => x.Humidity)
            };

            return(numberGroups.ToList());
        }
Пример #6
0
 public IActionResult Get()
 {
     _logger.LogDebug("Start New Request for controller {controller} and action {ActionName}", nameof(WeatherForecastController), nameof(Get));
     return(Ok(_weatherForecastRepository.GetAll()));
 }
Пример #7
0
 public async Task <IEnumerable <WeatherForecast> > GetForeCastSeries()
 {
     return(_repository.GetAll());
 }
 public IEnumerable <WeatherForecast> Get()
 {
     return(_repository.GetAll());
 }
Пример #9
0
 public IEnumerable <WeatherForecast> Execute()
 {
     return(_weatherForecastRepository.GetAll());
 }
Пример #10
0
 public async Task <IEnumerable <WeatherForecast> > Get()
 {
     return(await _weatherForecastRepository.GetAll());
 }