TrafficLightsCSharp/TrafficLights/Pages/GetStatus.cshtml.cs

30 lines
1.1 KiB
C#
Raw Normal View History

2023-11-04 11:02:30 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace TrafficLights.Pages
{
public class GetStatusModel : PageModel
{
private readonly TrafficLightSimulatorService _trafficLightSimulatorService;
public GetStatusModel(TrafficLightSimulatorService trafficLightSimulatorService)
{
_trafficLightSimulatorService = trafficLightSimulatorService;
}
public IActionResult OnGet()
{
var currentStatus = _trafficLightSimulatorService.GetStatus();
var data = new
{
currentPeriodName = currentStatus.CurrentPeriod.Name,
currentPeriodVerboseName = currentStatus.CurrentPeriod.VerboseName,
currentStateData = currentStatus.CurrentState,
currentStateIndex = currentStatus.CurrentStateIndex,
secondsUntilChangeover = currentStatus.SecondsUntilChangeover,
simulationTime = currentStatus.SimulationTime.ToString()
};
return new JsonResult(currentStatus);
}
}
}