using Microsoft.AspNetCore.Mvc; using ReportingServices.Shared.HelperClasses; using ReportingServices.Shared.Models.ProductionReport; using ReportingServices.Shared.ViewModels.ProductionReport; namespace ReportingServices.UI.Controllers { public class ProductionReportController : Controller { private readonly ILogger _logger; private readonly IConfiguration _configuration; private readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json"; private readonly string _toolStateOwnerFilePath = "wwwroot/Assets/ToolStates.json"; private readonly string _baseUrl; public ProductionReportController(ILogger logger, IConfiguration configuration) { _logger = logger; _configuration = configuration; _baseUrl = "http://localhost:50201/api/"; _logger.LogInformation("Base API Address: {baseUrl}", _baseUrl); } public IActionResult Index() { return View(); } public IActionResult DailyReport() { string baseFabTimeUrl = _baseUrl + "FabTime/"; string baseScrapeDbUrl = _baseUrl + "ScrapeDB/"; try { DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, baseFabTimeUrl, baseScrapeDbUrl); Dictionary> toolStateOwners = JsonFileHandler.LoadJSONFile>>(_toolStateOwnerFilePath); dailyReport.ToolStatesByOwner = toolStateOwners; return View(dailyReport); } catch (Exception ex) { _logger.LogCritical(ex, "Failed to load report"); return View(); } } public IActionResult EditDailyReport() { ManualReportEntries entries = JsonFileHandler.LoadJSONFile(_dailyRptFilePath); return View(entries); } [HttpPost] public IActionResult EditDailyReport(ManualReportEntries rpt) { JsonFileHandler.SaveJSONFile(rpt, _dailyRptFilePath); return RedirectToAction("DailyReport"); } } }