Files
SomniaGuestLog/src/Somnia.GuestLog/Models/EntityMapping.cs
T
Daniel-Garmig 54387a6346 StayExport Tracking - StayExportFile ExportDetails new type/format
- Added new class to unify and type the format of StayExportFile.ExportDetails field.

Note: This database migration will set to null all StayExportFile.ExportDetails data. This is required to prevent exceptions due to new formatting.
2026-10-09 12:58:23 +02:00

102 lines
3.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,
StayUploadStatus = entity.StayUploadStatus,
StayUploadStatusTime = entity.StayUploadStatusTime?.ToLocalTime(),
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,
};
StayExportDetailsDTO? detailsDTO = null;
if (entity.ExportDetails != null)
{
List<StayExportDetailsStayEntryDTO> entriesDto = [];
foreach (var entry in entity.ExportDetails.StayEntries)
{
entriesDto.Add(new()
{
StayEntryId = entry.StayEntryId,
ExportResult = entry.ExportResult,
Details = entry.Details,
});
}
detailsDTO = new()
{
ExportedStayCount = entity.ExportDetails.ExportedStayCount,
StayErrorCount = entity.ExportDetails.StayErrorCount,
StayEntries = entriesDto,
};
}
return new()
{
Id = entity.Id,
ExportFormat = entity.ExportFormat,
ExportParams = exportParamsDto,
ExportResult = entity.ExportResult,
ExportedPath = entity.ExportedPath,
ExportDetails = detailsDTO,
ExportTime = entity.ExportTime.ToLocalTime(),
FileUploadStatus = entity.FileUploadStatus,
FileUploadStatusTime = entity.FileUploadStatusTime?.ToLocalTime(),
};
}
}