From 1400532680e133ae6ec09df4b693aed74d646b8d Mon Sep 17 00:00:00 2001 From: Naz <2022755409@student.uitm.edu.my> Date: Tue, 15 Apr 2025 12:07:40 +0800 Subject: [PATCH] edit --- .../Views/Overtime/EditOvertime.cshtml | 341 +++++++++++++++++- .../Views/Overtime/OtRecords.cshtml | 4 +- .../Views/Overtime/OtRegister.cshtml | 3 +- Controllers/API/OvertimeAPI.cs | 46 ++- 4 files changed, 389 insertions(+), 5 deletions(-) diff --git a/Areas/OTcalculate/Views/Overtime/EditOvertime.cshtml b/Areas/OTcalculate/Views/Overtime/EditOvertime.cshtml index 4c42bf5..05503df 100644 --- a/Areas/OTcalculate/Views/Overtime/EditOvertime.cshtml +++ b/Areas/OTcalculate/Views/Overtime/EditOvertime.cshtml @@ -2,5 +2,344 @@ ViewData["Title"] = "Edit Overtime"; Layout = "~/Views/Shared/_Layout.cshtml"; } +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file +
+
+
+
+
+
+ + +
+ +
OFFICE HOURS
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
OUTSIDE OFFICE HOURS
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + + *Only for PSTW AIR +
+ + +
+ + + + {{ charCount }} / 150 characters + + +
+ +
+ +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + *upload pdf file only +
+ +
+ + +
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + +} \ No newline at end of file diff --git a/Areas/OTcalculate/Views/Overtime/OtRecords.cshtml b/Areas/OTcalculate/Views/Overtime/OtRecords.cshtml index 7d714b0..768f4e8 100644 --- a/Areas/OTcalculate/Views/Overtime/OtRecords.cshtml +++ b/Areas/OTcalculate/Views/Overtime/OtRecords.cshtml @@ -297,7 +297,7 @@ }, editRecord(index) { const record = this.filteredRecords[index]; - window.location.href = `/OTcalculate/Overtime/EditOvertime?id=${record.overtimeId}`; + window.location.href = `/OTcalculate/Overtime/EditOvertime?overtimeId=${record.overtimeId}`; }, async deleteRecord(index) { const record = this.filteredRecords[index]; @@ -322,7 +322,7 @@ const blobUrl = URL.createObjectURL(blob); const printWindow = window.open(blobUrl, '_blank'); - // Automatically trigger print after window loads + // Trigger print after window loads printWindow.onload = () => { printWindow.focus(); printWindow.print(); diff --git a/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml b/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml index e78b2ff..3f2569a 100644 --- a/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml +++ b/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml @@ -100,7 +100,8 @@
- + *upload pdf file only
diff --git a/Controllers/API/OvertimeAPI.cs b/Controllers/API/OvertimeAPI.cs index 18b5db7..519aeef 100644 --- a/Controllers/API/OvertimeAPI.cs +++ b/Controllers/API/OvertimeAPI.cs @@ -561,7 +561,6 @@ namespace PSTW_CentralSystem.Controllers.API .Where(o => o.UserId == userId && o.OtDate.Month == month && o.OtDate.Year == year) .ToList(); - // Optional: load logo image as byte array byte[]? logoImage = null; var logoPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "logo.jpg"); @@ -576,5 +575,50 @@ namespace PSTW_CentralSystem.Controllers.API #endregion + [HttpGet("GetOvertimeRecordById/{id}")] + public async Task GetOvertimeRecordById(int id) + { + var record = await _centralDbContext.Otregisters.FindAsync(id); + if (record == null) + return NotFound(); + + return Ok(record); + } + + [HttpPut("UpdateOvertimeRecord")] + public IActionResult UpdateOvertimeRecord([FromBody] OtRegisterModel model) + { + try + { + var existing = _centralDbContext.Otregisters.FirstOrDefault(o => o.OvertimeId == model.OvertimeId); + if (existing == null) + return NotFound("Overtime record not found."); + + // Update fields + existing.OtDate = model.OtDate; + existing.OfficeFrom = model.OfficeFrom; + existing.OfficeTo = model.OfficeTo; + existing.OfficeBreak = model.OfficeBreak; + existing.OutsideFrom = model.OutsideFrom; + existing.OutsideTo = model.OutsideTo; + existing.OutsideBreak = model.OutsideBreak; + existing.StationId = model.StationId; + existing.OtDescription = model.OtDescription; + existing.OtDays = model.OtDays; + existing.PDFBase64 = model.PDFBase64; + existing.UserId = model.UserId; + + _centralDbContext.SaveChanges(); + return Ok(new { message = "Record updated successfully." }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error updating overtime record."); + return StatusCode(500, "Failed to update record."); + } + } + + + } } \ No newline at end of file