77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ReportingServices.Shared.Repositories;
|
|
using ReportingServices.Shared.HelperClasses;
|
|
using ReportingServices.Shared.Models.ProductionReport;
|
|
using ReportingServices.Shared.ViewModels.ProductionReport;
|
|
|
|
namespace ReportingServices.UI.Controllers
|
|
{
|
|
public class ProductionReportController : Controller
|
|
{
|
|
private readonly IScrapeDatabaseRepository _scrapeDatabaseRepository;
|
|
private readonly IFabTimeReportingRepository _fabTimeReportingRepository;
|
|
private readonly ILogger<ProductionReportController> _logger;
|
|
private readonly int _reportIndex = (int)DateTime.Now.DayOfWeek;
|
|
private readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
|
|
private readonly string _toolStateOwnerFilePath = "wwwroot/Assets/ToolStates.json";
|
|
|
|
public ProductionReportController(IScrapeDatabaseRepository scrapeDatabaseRepository,
|
|
IFabTimeReportingRepository fabTimeReportingRepository, ILogger<ProductionReportController> logger)
|
|
{
|
|
_scrapeDatabaseRepository = scrapeDatabaseRepository;
|
|
_fabTimeReportingRepository = fabTimeReportingRepository;
|
|
_logger = logger;
|
|
}
|
|
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult DailyReport()
|
|
{
|
|
try
|
|
{
|
|
DailyReportHelper.SetRepositories(_fabTimeReportingRepository, _scrapeDatabaseRepository);
|
|
DailyReport dailyReport = DailyReportHelper.SetUpDailyReport().Result;
|
|
Dictionary<string, List<string>> toolStateOwners = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(_toolStateOwnerFilePath);
|
|
|
|
dailyReport.ToolStatesByOwner = toolStateOwners;
|
|
|
|
return View(dailyReport);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical(ex, "Failed to load report");
|
|
return View();
|
|
}
|
|
|
|
}
|
|
|
|
public IActionResult EditDailyReport()
|
|
{
|
|
Dictionary<string, List<ManualReportEntries>> entries = JsonFileHandler.LoadJSONFile<Dictionary<string, List<ManualReportEntries>>>(_dailyRptFilePath);
|
|
|
|
ManualReportEntries rpt = entries["Current Week"][_reportIndex];
|
|
|
|
return View(rpt);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult EditDailyReport(ManualReportEntries rpt)
|
|
{
|
|
Dictionary<string, List<ManualReportEntries>> report = JsonFileHandler.LoadJSONFile<Dictionary<string, List<ManualReportEntries>>>(_dailyRptFilePath);
|
|
|
|
rpt.Date = DateTime.Parse(DateTime.Now.ToShortDateString());
|
|
rpt.Day = DateTime.Now.DayOfWeek;
|
|
|
|
report["Current Week"][_reportIndex] = rpt;
|
|
|
|
JsonFileHandler.SaveJSONFile(report, _dailyRptFilePath);
|
|
|
|
return RedirectToAction("DailyReport");
|
|
}
|
|
}
|
|
}
|