/ src / GradeView / Data / WeatherForecastService.cs
WeatherForecastService.cs
 1  using System;
 2  using System.Linq;
 3  using System.Threading.Tasks;
 4  
 5  namespace GradeView.Data
 6  {
 7      public class WeatherForecastService
 8      {
 9          private static readonly string[] Summaries = new[]
10          {
11              "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12          };
13  
14          public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15          {
16              var rng = new Random();
17              WeatherForecast[] WeatherArray = new WeatherForecast[7];
18              for (int i = 0; i < 7; i++)
19              {
20                  DateTime Date = startDate.AddDays(i);
21                  int TemperatureC = rng.Next(-20, 50);
22                  string Summary = Summaries[(TemperatureC + 20) / 7];
23                  WeatherArray[i] = new WeatherForecast { Date = Date, TemperatureC = TemperatureC, Summary = Summary };
24              }
25              return Task.FromResult(WeatherArray);
26          }
27      }
28  }