| | 1 | | using Microsoft.AspNetCore.Mvc; |
| | 2 | | using ReportingServices.Shared.HelperClasses; |
| | 3 | | using ReportingServices.Shared.Models.ProductionReport; |
| | 4 | | using ReportingServices.Shared.ViewModels.ProductionReport; |
| | 5 | |
|
| | 6 | | namespace ReportingServices.UI.Controllers |
| | 7 | | { |
| | 8 | | public class ProductionReportController : Controller |
| | 9 | | { |
| | 10 | | private readonly ILogger<ProductionReportController> _logger; |
| 0 | 11 | | private readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json"; |
| 0 | 12 | | private readonly string _toolStateOwnerFilePath = "wwwroot/Assets/ToolStates.json"; |
| | 13 | |
|
| 0 | 14 | | public ProductionReportController(ILogger<ProductionReportController> logger) |
| 0 | 15 | | { |
| 0 | 16 | | _logger = logger; |
| 0 | 17 | | } |
| | 18 | |
|
| | 19 | |
|
| | 20 | | public IActionResult Index() |
| 0 | 21 | | { |
| 0 | 22 | | return View(); |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public IActionResult DailyReport() |
| 0 | 26 | | { |
| | 27 | | try |
| 0 | 28 | | { |
| 0 | 29 | | DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(); |
| 0 | 30 | | Dictionary<string, List<string>> toolStateOwners = JsonFileHandler.LoadJSONFile<Dictionary<string, List< |
| | 31 | |
|
| 0 | 32 | | dailyReport.ToolStatesByOwner = toolStateOwners; |
| | 33 | |
|
| 0 | 34 | | return View(dailyReport); |
| | 35 | | } |
| 0 | 36 | | catch (Exception ex) |
| 0 | 37 | | { |
| 0 | 38 | | _logger.LogCritical(ex, "Failed to load report"); |
| 0 | 39 | | return View(); |
| | 40 | | } |
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | public IActionResult EditDailyReport() |
| 0 | 44 | | { |
| 0 | 45 | | ManualReportEntries entries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath); |
| | 46 | |
|
| 0 | 47 | | return View(entries); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | [HttpPost] |
| | 51 | | public IActionResult EditDailyReport(ManualReportEntries rpt) |
| 0 | 52 | | { |
| 0 | 53 | | JsonFileHandler.SaveJSONFile(rpt, _dailyRptFilePath); |
| | 54 | |
|
| 0 | 55 | | return RedirectToAction("DailyReport"); |
| 0 | 56 | | } |
| | 57 | | } |
| | 58 | | } |