private void Configure(ConverterConfigurator <SecondContractDocument <SecondContractDocumentBody>, SecondContractDocumentBody, InnerDocument, InnerDocument, InnerDocument> subConfigurator) { subConfigurator.Target(data => data.OrdersNumber).Set(message => message.BeginningOfMessage.DocumentMessageIdentification.DocumentIdentifier); subConfigurator.ConfigureDateOrUtcNow("137", data => data.OrdersDate); subConfigurator.ConfigureDate("50", data => data.ReceivingDate); subConfigurator.Target(data => data.CurrencyCode).Set(message => (from details in message.Currency.CurrencyDetails where details.UsageCodeQualifier == "2" && details.TypeCodeQualifier == "4" select details.IdentificationCode).FirstOrDefault(), s => defaultConverter.Convert(s)); subConfigurator.Target(data => data.FlowType).Set(message => message.FreeText.Any(y => y.TextSubjectCodeQualifier == "DEL") ? defaultConverter.Convert(message.FreeText.FirstOrDefault(y => y.TextSubjectCodeQualifier == "DEL").TextReference.FreeTextValueCode) : message.FreeText.Any(y => y.TextSubjectCodeQualifier == "ZZZ" && y.TextLiteral.FreeTextValue[0] == "Fresh") ? "fresh" : defaultConverter.Convert(message.SG28.FirstOrDefault().FreeText.FirstOrDefault(y => y.TextSubjectCodeQualifier == "DEL" && y.TextReference.CodeListResponsibleAgencyCode == "ZZZ").TextReference.FreeTextValueCode)); subConfigurator.Target(data => data.TransportDetails.VehicleNumber) .Set(message => message.SG10.FirstOrDefault(sg10 => sg10.DetailsOfTransport.TransportStageCodeQualifier == "1").DetailsOfTransport.TransportIdentification.TransportMeansIdentificationName); subConfigurator.Target(data => data.FreeText).Set(message => ArrayStringConverter.ToString(message.FreeText.FirstOrDefault(freeText => freeText.TextSubjectCodeQualifier == "ZZZ" || freeText.TextSubjectCodeQualifier == "PUR" || freeText.TextSubjectCodeQualifier == "AAI").TextLiteral.FreeTextValue)); subConfigurator.GoTo(x => x, x => x.References).ConfigureReference("BO", data => data.BlanketOrdersNumber); subConfigurator.If(message => !string.IsNullOrEmpty(message.ControlTotal.FirstOrDefault(cnt => cnt.Control.ControlTotalTypeCodeQualifier == "11").Control.ControlTotalValue)) .Target(data => data.OrdersTotalPackageQuantity) .Set(message => decimalConverter.ToDecimal(message.ControlTotal.FirstOrDefault(cnt => cnt.Control.ControlTotalTypeCodeQualifier == "11").Control.ControlTotalValue)); subConfigurator.ConfigureMonetaryAmountsInfo(new MonetaryAmountConfig <InnerDocument>("79", x => x.RecadvTotal), new MonetaryAmountConfig <InnerDocument>(new[] { "77", "9" }, x => x.TotalWithVAT)); subConfigurator.GoTo(x => x.DespatchParties.Each().PartyInfo, message => message.PartiesArray.Where(sg2 => sg2.NameAndAddress.PartyFunctionCodeQualifier == "PW").Current()) .ConfigureParty <SecondContractDocument <SecondContractDocumentBody>, InnerDocument, SG2, SG3, SG5>(); subConfigurator.GoTo(data => data.Transports.Each(), message => message.SG10.Where(sg10 => sg10.DetailsOfTransport.TransportStageCodeQualifier == "20") .SelectMany(sg10 => DefaultIfNullOrEmpty(sg10.SG11), (sg10, sg11) => new { sg10.DetailsOfTransport.TransportMeans.TransportMeansDescription, TypeOfTransportCode = defaultConverter.Convert(sg10.DetailsOfTransport.TransportMeans.TransportMeansDescriptionCode), sg11.DateTimePeriod }) .Where(x => !string.IsNullOrEmpty(x.TypeOfTransportCode) || !string.IsNullOrEmpty(x.TransportMeansDescription) || x.DateTimePeriod != null) .Current()) .BatchSet((x, y) => new Batch { { x.TypeOfTransport, y.TransportMeansDescription }, { x.TypeOfTransportCode, y.TypeOfTransportCode }, { x.DeliveryDateForVehicle, dateTimePeriodConverter.ToDateTime(y.DateTimePeriod.FirstOrDefault(period => period.DateTimePeriodGroup.FunctionCodeQualifier == "232").DateTimePeriodGroup) }, }); ConfigureGoodItems(subConfigurator.GoTo(data => data.GoodItems.Each(), message => message.SG28.Current())); }