46 lines
1.2 KiB
C#
46 lines
1.2 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);
|
|
|
|
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)
|
|
{
|
|
var cityRoadLengthStats = _dataService.GetCityRoadLengthStats(city);
|
|
return View(new CityModel(city, cityRoadLengthStats));
|
|
}
|
|
|
|
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 });
|
|
}
|
|
}
|