-
Notifications
You must be signed in to change notification settings - Fork 352
/
Copy pathWeatherForecastService.cs
49 lines (42 loc) · 1.45 KB
/
WeatherForecastService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PopupControl.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private List<WeatherForecast> Forecasts { get; set; } = new List<WeatherForecast>();
public WeatherForecastService()
{
var rng = new Random();
this.Forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Id = index,
Date = DateTime.Today.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToList();
}
public Task<List<WeatherForecast>> GetForecastAsync()
{
return Task.FromResult(this.Forecasts);
}
public Task<WeatherForecast> GetLastForecastAsync()
{
return Task.FromResult(this.Forecasts.OrderByDescending(o => o.Id).First());
}
public Task<WeatherForecast> GetForecastAsync(int id)
{
return Task.FromResult(this.Forecasts.Where(o => o.Id == id).FirstOrDefault());
}
public void AddForecast(WeatherForecast forecast)
{
this.Forecasts.Add(forecast);
}
}
}