Advertisement
Guest User

SampleDataController.cs

a guest
Sep 16th, 2018
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6.  
  7. namespace WebApplication6.Controllers
  8. {
  9.     [Route("api/[controller]")]
  10.     public class SampleDataController : Controller
  11.     {
  12.         private static string[] Summaries = new[]
  13.         {
  14.             "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
  15.         };
  16.  
  17.         [HttpGet("[action]")]
  18.         public IEnumerable<WeatherForecast> WeatherForecasts()
  19.         {
  20.             var rng = new Random();
  21.             return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  22.             {
  23.                 DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
  24.                 TemperatureC = rng.Next(-20, 55),
  25.                 Summary = Summaries[rng.Next(Summaries.Length)]
  26.             });
  27.         }
  28.  
  29.         public class WeatherForecast
  30.         {
  31.             public string DateFormatted { get; set; }
  32.             public int TemperatureC { get; set; }
  33.             public string Summary { get; set; }
  34.  
  35.             public int TemperatureF
  36.             {
  37.                 get
  38.                 {
  39.                     return 32 + (int)(TemperatureC / 0.5556);
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement