Files
PL_JusticeBot/Controllers/WeatherForecastController.cs
Дмитрий Шиманский dde8b38520 updated
2023-11-09 00:24:18 +03:00

40 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
namespace DiscordApp.Controllers
{
[ApiController]
[Route("[controller]")]
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(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
public static async Task<bool> isAllowed(IServiceProvider services)
{
var context = services.GetRequiredService<ActionContext>();
if (context.HttpContext.Request.Cookies["geff"] == "ok") { return true; }
else { return false; }
}
}
}