Files
SomniaGuestLog/src/Somnia.GuestLog/Models/EntityMapping.cs
T
Daniel-Garmig c5d8487046 Small fixes and improvements:
- GuestDocument - At least one contact field is required.
- GuestDocument - List Page - Hide not useful columns: "version"
- StayEntry - Show stayEntry ID in UI msg after creation.
- StayEntry - Create Page - Time fields don't reset anymore when dates change.
- Show local times in UI instead of UTC times.
- Validators - Use expresions for dates so they are recalculated each time.
2026-09-12 15:28:25 +02:00

76 lines
2.8 KiB
C#

using Somnia.GuestLog.Models.DTOs;
using Somnia.GuestLog.Models.Entities;
namespace Somnia.GuestLog.Models;
internal static class EntityMapping
{
public static GuestDocumentDTO MapGuestDocumentEntityToDTO(GuestDocument entity)
{
return new()
{
Id = entity.Id,
Version = entity.Version,
DocumentType = entity.DocumentType,
DocumentNum = entity.DocumentNum,
IssueDate = entity.IssueDate?.ToDateTime(TimeOnly.MinValue) ?? null,
SupportNum = entity.SupportNum,
Nationality = entity.Nationality,
Name = entity.Name,
Surname = entity.Surname,
Surname2 = entity.Surname2,
BirthDate = entity.BirthDate.ToDateTime(TimeOnly.MinValue),
Gender = entity.Gender,
PhoneNumber = entity.PhoneNumber,
EmailAddress = entity.EmailAddress,
Address = entity.AddressDetails?.Address ?? "",
AddressCity = entity.AddressDetails?.AddressCity ?? "",
AddressProvince = entity.AddressDetails?.AddressProvince ?? "",
AddressState = entity.AddressDetails?.AddressState ?? "",
AddressCountry = entity.AddressDetails?.AddressCountry! ?? "",
ZipCode = entity.AddressDetails?.ZipCode ?? "",
CreateTime = entity.CreateTime.ToLocalTime(),
UpdateTime = entity.UpdateTime.ToLocalTime(),
};
}
public static StayEntryDTO MapStayEntryEntityToDTO(StayEntry entity, bool includeGuests)
{
return new()
{
Id = entity.Id,
DateIn = entity.DateIn.ToLocalTime(),
DateOut = entity.DateOut.ToLocalTime(),
RoomCount = entity.RoomCount,
RoomNumber = entity.RoomNumber,
PaymentMethod = entity.PaymentMethod,
CreateTime = entity.CreateTime.ToLocalTime(),
UpdateTime = entity.UpdateTime.ToLocalTime(),
GuestDocuments = includeGuests ? [.. entity.GuestDocuments.Select(e => MapGuestDocumentEntityToDTO(e))] : null,
};
}
public static StayExportFileDTO MapStayExportFileEntityToDTO(StayExportFile entity)
{
StayExportParamsDTO exportParamsDto = new()
{
ExportType = entity.ExportParams.ExportType,
ExportPeriodStart = entity.ExportParams.ExportPeriodStart,
ExportPeriodEnd = entity.ExportParams.ExportPeriodEnd,
};
return new()
{
Id = entity.Id,
ExportFormat = entity.ExportFormat,
ExportParams = exportParamsDto,
ExportResult = entity.ExportResult,
ExportedPath = entity.ExportedPath,
ExportDetails = entity.ExportDetails,
ExportTime = entity.ExportTime.ToLocalTime(),
};
}
}