Files
yongestreet/YongeStreet/Controllers/HomeController.cs
T
2025-01-11 21:26:33 -05:00

55 lines
1.6 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(List<CityOverview> Cities);
public record TmpModel(IList<string> 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 CityList_Partial(string? search)
{
var cities = _dataService.GetCityOverview(search??"");
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 });
}
}