Files
yongestreet/YongeStreet/Controllers/HomeController.cs
T
2025-01-05 19:43:30 -05:00

47 lines
1.3 KiB
C#

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using YongeStreet.Models;
using YongeStreet.Services;
namespace YongeStreet.Controllers;
public record CityModel(string City, IList<CityRoadLengthStats> CityRoadLengthStats, DateOnly Date);
public record IndexModel(IList<CityOverview> Cities);
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly DataService _dataService;
public HomeController(ILogger<HomeController> logger, DataService dataService)
{
_logger = logger;
_dataService = dataService;
}
public IActionResult City(string city, string date)
{
var cityRoadLengthStats = _dataService.GetCityRoadLengthStats(city);
var parsedDate = Util.ParseDateOnly(date) ?? new DateOnly(2025, 1, 1);
return View(new CityModel(city, cityRoadLengthStats, parsedDate ));
}
public IActionResult Index()
{
var cities = _dataService.GetCityOverview();
return View(new IndexModel(cities));
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}