From 4fea4164fad943eebc1850042994fdbaad3682f9 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 4 Feb 2019 23:25:33 +0800 Subject: Init commit. --- Timeline/Controllers/SampleDataController.cs | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Timeline/Controllers/SampleDataController.cs (limited to 'Timeline/Controllers/SampleDataController.cs') diff --git a/Timeline/Controllers/SampleDataController.cs b/Timeline/Controllers/SampleDataController.cs new file mode 100644 index 00000000..04e7f127 --- /dev/null +++ b/Timeline/Controllers/SampleDataController.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Timeline.Controllers +{ + [Route("api/[controller]")] + public class SampleDataController : Controller + { + private static string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + [HttpGet("[action]")] + [Authorize] + public IEnumerable WeatherForecasts() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + DateFormatted = DateTime.Now.AddDays(index).ToString("d"), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }); + } + + public class WeatherForecast + { + public string DateFormatted { get; set; } + public int TemperatureC { get; set; } + public string Summary { get; set; } + + public int TemperatureF + { + get + { + return 32 + (int)(TemperatureC / 0.5556); + } + } + } + } +} -- cgit v1.2.3