//Constructor
        public EmployeeRecordsMapping()
        {
            AutoMap();

            //Convert payment date time to payment period.
            Map(s => s.PaymentStartDate).ConvertUsing(x =>
            {
                string date = x.GetField(PaymentStartDateField);
                PaymentPeriod.TryParseFromDateRangeString(date, out var paymentPeriod);
                return(paymentPeriod);
            }

                                                      );

            //Trim % from inpout record and return percentage.
            Map(x => x.SuperRate).ConvertUsing(x =>
            {
                string superRate    = x.GetField(SuperRateField);
                string trimmedValue = superRate.Trim('%');
                if (Decimal.TryParse(trimmedValue, out decimal result))
                {
                    return(result / 100);
                }
                throw new InvalidCastException("Unable to parse Super Rate field - Unrecognized  Value : " + superRate);
            }

                                               );
        }
Пример #2
0
        // ReSharper disable once UnusedMember.Global
        public EmployeeClassMapping()
        {
            AutoMap(CultureInfo.InvariantCulture);
            Map(x => x.SuperRate)
            .ConvertUsing(r =>
            {
                var value   = r.GetField(SuperRateField);
                var trimmed = value.Trim(new[] { '%', ' ' });
                if (Decimal.TryParse(trimmed, out decimal result))
                {
                    return(result / 100);
                }

                throw new InvalidOperationException(
                    $"Unable to parse {SuperRateField} - Unrecognised percentage value: {value}");
            });
            Map(x => x.PaymentStartDate)
            .ConvertUsing(x =>
            {
                var dateRange = x.GetField(PaymentStartDateField);
                PaymentPeriod.TryParseFromDateRangeString(dateRange, out var paymentPeriod);
                return(paymentPeriod);
            });
        }