Files
SomniaGuestLog/src/Somnia.GuestLog/Models/EntityMapping.cs
T
Daniel-Garmig 0abdfcd683 GuestDocument - Improvements to GuestDocument creation:
- IssueDate is now Nullable. Is not required for DNI and NIE document types.
- Improvements in SupportNumber for NIE documents.
- Address search can now be skipped.
2026-09-10 11:53:41 +02:00

76 lines
2.7 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,
UpdateTime = entity.UpdateTime,
};
}
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,
UpdateTime = entity.UpdateTime,
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,
};
}
}