private void populateDataWithFieldValues(FieldMap[] fieldMaps, ClarifyDataRow record, ModelData model)
        {
            var tableName = record.Table.TableName;

            if (tableName.Contains(":"))
            {
                tableName = tableName.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries).Last();
            }

            var tableMetadata = _metadata.MetadataFor(tableName);

            foreach (var fieldMap in fieldMaps)
            {
                if (fieldMap.Key.IsEmpty())
                {
                    continue;
                }

                try
                {
                    var fieldMetadata = fieldMap.FieldNames.Length == 1
                                                ? tableMetadata.MetadataFor(fieldMap.FieldNames[0])
                                                : new FieldSchemaMetadata();

                    var propertyValue = GetFieldValueForRecord(fieldMap, record);

                    if (propertyValue is string && fieldMap.ShouldEncode)
                    {
                        propertyValue = _encoder.Encode((string)propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(int))
                    {
                        propertyValue = Convert.ToInt32(propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(DateTime))
                    {
                        var dateTime = Convert.ToDateTime(propertyValue);
                        if (fieldMetadata.IsDateOnlyField())
                        {
                            propertyValue = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, DateTimeKind.Utc);
                        }
                        else
                        {
                            var utcDateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc);
                            propertyValue = utcDateTime;
                        }
                    }

                    model[fieldMap.Key] = propertyValue;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(model.GetType().Name, fieldMap.ToString()), ex);
                }
            }
        }
        private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto)
        {
            foreach (var fieldMap in genericMap.FieldMaps)
            {
                if (fieldMap.Property == null)
                {
                    continue;
                }

                var propertyValue = GetFieldValueForRecord(fieldMap, record);

                if (propertyValue is string && fieldMap.ShouldEncode)
                {
                    propertyValue = _outputEncoder.Encode((string)propertyValue);
                }

                if (fieldMap.Property.PropertyType == typeof(int))
                {
                    propertyValue = Convert.ToInt32(propertyValue);
                }

                if (fieldMap.Property.PropertyType == typeof(DateTime))
                {
                    var dateTime    = Convert.ToDateTime(propertyValue);
                    var utcDateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc);
                    propertyValue = utcDateTime;
                }

                try
                {
                    fieldMap.Property.SetValue(dto, propertyValue, null);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(dto.GetType().Name, fieldMap.ToString()), ex);
                }
            }
        }
        private void populateDataWithFieldValues(FieldMap[] fieldMaps, ClarifyDataRow record, ModelData model)
        {
            foreach (var fieldMap in fieldMaps)
            {
                if (fieldMap.Key.IsEmpty())
                {
                    continue;
                }

                try
                {
                    var propertyValue = GetFieldValueForRecord(fieldMap, record);

                    if (propertyValue is string && fieldMap.ShouldEncode)
                    {
                        propertyValue = _encoder.Encode((string)propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(int))
                    {
                        propertyValue = Convert.ToInt32(propertyValue);
                    }

                    if (fieldMap.PropertyType == typeof(DateTime))
                    {
                        var dateTime    = Convert.ToDateTime(propertyValue);
                        var utcDateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc);
                        propertyValue = utcDateTime;
                    }

                    model[fieldMap.Key] = propertyValue;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(model.GetType().Name, fieldMap.ToString()), ex);
                }
            }
        }