150 lines
5.2 KiB
C#
150 lines
5.2 KiB
C#
using UtopiaCanteen.Shared;
|
|
using UtopiaCanteenSystem.Models;
|
|
using UtopiaCanteenSystem.Services;
|
|
|
|
namespace UtopiaCanteenSystem.Api;
|
|
|
|
public static class ApiDtoMapper
|
|
{
|
|
public static EmployeeDto? ToEmployeeDto(HrmsEmployeeInfo? e)
|
|
{
|
|
if (e == null) return null;
|
|
return new EmployeeDto
|
|
{
|
|
ParentDocumentId = e.ParentDocumentId,
|
|
EmployeeId = e.EmployeeId,
|
|
UindSerial = e.UindSerial,
|
|
FunctionId = e.FunctionId,
|
|
DepartmentId = e.DepartmentId,
|
|
TagCreatedAtUtc = e.TagCreatedAtUtc,
|
|
TagCreatedBy = e.TagCreatedBy,
|
|
FirstName = e.FirstName,
|
|
MiddleName = e.MiddleName,
|
|
DepartmentTitle = e.DepartmentTitle,
|
|
DepartmentType = e.DepartmentType,
|
|
LocationSiteId = e.LocationSiteId,
|
|
GradeType = e.GradeType
|
|
};
|
|
}
|
|
|
|
public static HrmsEmployeeInfo ToModel(EmployeeDto e) => new()
|
|
{
|
|
ParentDocumentId = e.ParentDocumentId ?? string.Empty,
|
|
EmployeeId = e.EmployeeId ?? string.Empty,
|
|
UindSerial = e.UindSerial ?? string.Empty,
|
|
FunctionId = e.FunctionId,
|
|
DepartmentId = e.DepartmentId,
|
|
TagCreatedAtUtc = e.TagCreatedAtUtc,
|
|
TagCreatedBy = e.TagCreatedBy ?? string.Empty,
|
|
FirstName = e.FirstName ?? string.Empty,
|
|
MiddleName = e.MiddleName ?? string.Empty,
|
|
DepartmentTitle = e.DepartmentTitle ?? string.Empty,
|
|
DepartmentType = e.DepartmentType ?? string.Empty,
|
|
LocationSiteId = e.LocationSiteId ?? string.Empty,
|
|
GradeType = e.GradeType ?? string.Empty
|
|
};
|
|
|
|
public static ScanResponse ToScanResponse(ScanResult r, string? mealLabel = null, string? mealItems = null, double totalPrice = 0) =>
|
|
new()
|
|
{
|
|
Success = r.Success,
|
|
Message = r.Message,
|
|
CooldownSecondsRemaining = r.CooldownSecondsRemaining,
|
|
Employee = ToEmployeeDto(r.EmployeeInfo),
|
|
MealSession = (int)r.MealSession,
|
|
EmployeeSiteId = r.EmployeeSiteId,
|
|
CurrentSiteId = r.CurrentSiteId,
|
|
MealLabel = mealLabel,
|
|
MealItems = mealItems,
|
|
TotalPrice = totalPrice
|
|
};
|
|
|
|
public static RecentScanDto ToRecentScanDto(ScanRecord r) => new()
|
|
{
|
|
Id = r.Id,
|
|
CardId = r.CardId,
|
|
ScanTime = r.ScanTime,
|
|
IsSynced = r.IsSynced,
|
|
SiteId = r.SiteId,
|
|
DeviceId = r.DeviceId,
|
|
IpAddress = r.IpAddress,
|
|
MealSessionCode = r.MealSessionCode,
|
|
ParentDocumentId = r.ParentDocumentId,
|
|
EmployeeId = r.EmployeeId,
|
|
UindSerial = r.UindSerial,
|
|
FunctionId = r.FunctionId,
|
|
DepartmentId = r.DepartmentId,
|
|
TagCreatedAtUtc = r.TagCreatedAtUtc,
|
|
TagCreatedBy = r.TagCreatedBy,
|
|
EmployeeName = r.EmployeeName,
|
|
Department = r.Department,
|
|
DepartmentType = r.DepartmentType,
|
|
MealLabel = r.MealLabel,
|
|
MealItems = r.MealItems,
|
|
TotalPrice = r.TotalPrice,
|
|
GradeType = r.grade_type
|
|
};
|
|
|
|
public static ScanRecord ToEntity(RecentScanDto d) => new()
|
|
{
|
|
Id = d.Id,
|
|
CardId = d.CardId ?? string.Empty,
|
|
ScanTime = d.ScanTime,
|
|
IsSynced = d.IsSynced,
|
|
SiteId = d.SiteId ?? string.Empty,
|
|
DeviceId = d.DeviceId ?? string.Empty,
|
|
IpAddress = d.IpAddress ?? string.Empty,
|
|
MealSessionCode = d.MealSessionCode,
|
|
ParentDocumentId = d.ParentDocumentId ?? string.Empty,
|
|
EmployeeId = d.EmployeeId ?? string.Empty,
|
|
UindSerial = d.UindSerial ?? string.Empty,
|
|
FunctionId = d.FunctionId,
|
|
DepartmentId = d.DepartmentId,
|
|
TagCreatedAtUtc = d.TagCreatedAtUtc,
|
|
TagCreatedBy = d.TagCreatedBy ?? string.Empty,
|
|
EmployeeName = d.EmployeeName ?? string.Empty,
|
|
Department = d.Department ?? string.Empty,
|
|
DepartmentType = d.DepartmentType ?? string.Empty,
|
|
MealLabel = d.MealLabel ?? string.Empty,
|
|
MealItems = d.MealItems ?? string.Empty,
|
|
TotalPrice = d.TotalPrice,
|
|
grade_type = d.GradeType ?? string.Empty
|
|
};
|
|
|
|
public static ManualSyncResponse ToManualSync(bool success, string message, DateTime? started, DateTime? completed, string? details = null) =>
|
|
new()
|
|
{
|
|
Success = success,
|
|
Message = message,
|
|
StartedAt = started,
|
|
CompletedAt = completed,
|
|
Details = details
|
|
};
|
|
|
|
public static MealScheduleDto ToMealScheduleDto(MealSchedule s) => new()
|
|
{
|
|
Id = s.Id,
|
|
MealName = s.MealName,
|
|
LocationSiteId = s.LocationSiteId,
|
|
MealSession = s.MealSession,
|
|
StartTime = s.StartTime,
|
|
EndTime = s.EndTime,
|
|
IsActive = s.IsActive,
|
|
CreatedAt = s.CreatedAt,
|
|
UpdatedAt = s.UpdatedAt
|
|
};
|
|
|
|
public static MealSchedule ToMealSchedule(MealScheduleDto d) => new()
|
|
{
|
|
Id = d.Id,
|
|
MealName = d.MealName ?? string.Empty,
|
|
LocationSiteId = d.LocationSiteId ?? string.Empty,
|
|
MealSession = d.MealSession,
|
|
StartTime = d.StartTime ?? string.Empty,
|
|
EndTime = d.EndTime ?? string.Empty,
|
|
IsActive = d.IsActive,
|
|
CreatedAt = d.CreatedAt,
|
|
UpdatedAt = d.UpdatedAt
|
|
};
|
|
}
|