PSTW_CentralizeSystem/Areas/OTcalculate/Models/OtRegisterModel.cs
2025-04-21 17:24:48 +08:00

46 lines
1.5 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; }
// 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;
}
}
}