public IActionResult Forecasts([FromQuery(Name = "from")] int from = 0, [FromQuery(Name = "to")] int to = 4)
        {
            var quantity = to - from;

            // We should also avoid going too far in the list.
            if (quantity <= 0)
            {
                return(BadRequest("You cannot have the 'to' parameter higher than 'from' parameter."));
            }

            if (from < 0)
            {
                return(BadRequest("You cannot go in the negative with the 'from' parameter"));
            }

            var allForecasts = weatherProvider.GetForecasts();
            var result       = new WeatherForecastResults
            {
                Total     = allForecasts.Count,
                Forecasts = allForecasts.Skip(from).Take(quantity).ToArray()
            };

            return(Ok(result));
        }
Exemple #2
0
 public IEnumerable <WeatherForecast> Get()
 {
     return(WeatherForecastResults.GetForecast());
 }