-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathWeatherForecastController.cs
More file actions
76 lines (69 loc) · 1.78 KB
/
Copy pathWeatherForecastController.cs
File metadata and controls
76 lines (69 loc) · 1.78 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Api.Controllers
{
[ApiController]
[Route("api")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing",
"Bracing",
"Chilly",
"Cool",
"Mild",
"Warm",
"Balmy",
"Hot",
"Sweltering",
"Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet("weatherforecasts")]
public IEnumerable<WeatherForecast> WeatherForecasts(int count = 10)
{
var rng = new Random();
return Enumerable
.Range(1, count)
.Select(
index =>
new WeatherForecast
{
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}
);
}
[HttpGet("weatherforecastsplus")]
[Authorize]
public IEnumerable<WeatherForecast> WeatherForecastsPlus(int count = 10)
{
return WeatherForecasts(count);
}
public class WeatherForecast
{
public string Id
{
get { return Guid.NewGuid().ToString(); }
}
public string DateFormatted { get; set; } = string.Empty;
public int TemperatureC { get; set; }
public string Summary { get; set; } = string.Empty;
public int TemperatureF
{
get { return 32 + (int)(TemperatureC / 0.5556); }
}
}
}
}