I have a part of code that works for in the service.cs but I need move to this code and conditons to mapping. This is my origin code:
location.Documents.ForEach(x => {
var isModifiedOneHourAgo = (x.RejectedAt.HasValue || x.ApprovedAt.HasValue) && x.CreatedAt >= (int)DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeSeconds() ? true : (!x.RejectedAt.HasValue && !x.ApprovedAt.HasValue);
var isDocumentWayyBillAndDeliveryRecepitisUploaded = x.Type.ToString() == DocumentDefinitionGuids.WAYBILL ? !location.Documents.Any(x => x.Type.ToString() == DocumentDefinitionGuids.DELIVERY_RECEIPT) : true;
var isDocumentOwner = x.CreatedBy == this.userSession.UserId.ToString();
});
However, I could not manage to implement this on mappings. So far what I have tried:
.Map(dest => dest.CargoLocations.Select(x => x.Documents), src => src.CargoLocations.Select(cargoLocation => {
var isModifiedOneHourAgo = cargoLocation.Documents.Any(document => (document.Upload.RejectedAt.HasValue || document.Upload.ApprovedAt.HasValue) && document.Upload.CreatedAt >= (int)DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeSeconds()) || (!cargoLocation.Documents.Any(document => document.Upload.RejectedAt.HasValue || document.Upload.ApprovedAt.HasValue));
var isDocumentWayBillAndDeliveryRecepitisUploaded = cargoLocation.Documents.Any(documents => (documents.DocumentDefinitionId.ToString() == DocumentDefinitionGuids.WAYBILL ? !cargoLocation.Documents.Any(document => cargoLocation.Documents.Any(document => document.DocumentDefinitionId.ToString() == DocumentDefinitionGuids.DELIVERY_RECEIPT)) : true));
var isDocumentOwner = cargoLocation.Documents.Any(document => (string)MapContext.Current.Parameters["UserId"] == document.Upload.CreatedBy);
return isModifiedOneHourAgo && isDocumentWayBillAndDeliveryRecepitisUploaded && isDocumentOwner;
}).ToList())
cargolocations has documents list -> documents list has uploads