PSTW_CentralizeSystem/Areas/OTcalculate/Models/OtRegisterModel.cs
2025-06-09 14:41:52 +08:00

100 lines
3.8 KiB
C#

using PSTW_CentralSystem.Areas.Inventory.Models;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PSTW_CentralSystem.Areas.OTcalculate.Models
{
[Table("otregisters")]
public class OtRegisterModel
{
[Key]
public int OvertimeId { get; set; }
[Required]
public DateTime OtDate { get; set; }
public TimeSpan? OfficeFrom { get; set; }
public TimeSpan? OfficeTo { get; set; }
public int? OfficeBreak { get; set; }
public TimeSpan? AfterFrom { get; set; }
public TimeSpan? AfterTo { get; set; }
public int? AfterBreak { get; set; }
public int? StationId { get; set; }
[ForeignKey("StationId")]
public virtual StationModel? Stations { get; set; }
public string OtDescription { get; set; }
public string OtDays { get; set; }
[Required]
public int UserId { get; set; }
public int? StatusId { get; set; }
[ForeignKey("StatusId")]
public virtual OtStatusModel? Otstatus { get; set; }
// Convert string times to TimeSpan before saving
public TimeSpan? GetOfficeFrom() => ParseTimeSpan(OfficeFrom?.ToString());
public TimeSpan? GetOfficeTo() => ParseTimeSpan(OfficeTo?.ToString());
public TimeSpan? GetAfterFrom() => ParseTimeSpan(AfterFrom?.ToString());
public TimeSpan? GetAfterTo() => ParseTimeSpan(AfterTo?.ToString());
private TimeSpan? ParseTimeSpan(string? time)
{
return TimeSpan.TryParse(time, out TimeSpan result) ? result : null;
}
// OtRegisterEditDto.cs
public class OtRegisterEditDto
{
public int OvertimeId { get; set; }
public DateTime OtDate { get; set; }
public string? OfficeFrom { get; set; } // Use string to match input type (e.g., "09:00")
public string? OfficeTo { get; set; } // Use string to match input type
public int? OfficeBreak { get; set; }
public string? AfterFrom { get; set; } // Use string to match input type
public string? AfterTo { get; set; } // Use string to match input type
public int? AfterBreak { get; set; }
public int? StationId { get; set; }
public string? OtDescription { get; set; }
// You might also need to send the StatusId if it's relevant for the update logic
public int StatusId { get; set; }
public string? OtDays { get; set; }
}
public class OtUpdateLog
{
public string ApproverRole { get; set; } // e.g., "HoU", "HoD", "Manager", "HR"
public int ApproverUserId { get; set; }
public DateTime UpdateTimestamp { get; set; }
public string ChangeType { get; set; } // New: "Edit" or "Delete"
// For "Edit" type
public OtRegisterModel? BeforeEdit { get; set; }
public OtRegisterEditDto? AfterEdit { get; set; }
// For "Delete" type
public OtRegisterModel? DeletedRecord { get; set; }
}
public class OtRegisterUpdateDto
{
public int OvertimeId { get; set; }
public DateTime OtDate { get; set; }
public string? OfficeFrom { get; set; }
public string? OfficeTo { get; set; }
public int? OfficeBreak { get; set; }
public string? AfterFrom { get; set; }
public string? AfterTo { get; set; }
public int? AfterBreak { get; set; }
public int? StationId { get; set; }
public string? OtDescription { get; set; }
public string? OtDays { get; set; }
public int UserId { get; set; }
}
}
}