public static TCommand ToCommand <TCommand, TDto>(TDto dto, TCommand command) where TCommand : UpsertCommand where TDto : UpsertDto { SimpleMapper.Map(dto, command); if (dto.Properties != null) { command.Properties = new SchemaProperties(); SimpleMapper.Map(dto.Properties, command.Properties); } if (dto.Scripts != null) { command.Scripts = new SchemaScripts(); SimpleMapper.Map(dto.Scripts, command.Scripts); } if (dto.Fields != null) { command.Fields = new List <UpsertSchemaField>(); foreach (var rootFieldDto in dto.Fields) { var rootProps = rootFieldDto?.Properties.ToProperties(); var rootField = new UpsertSchemaField { Properties = rootProps }; SimpleMapper.Map(rootFieldDto, rootField); if (rootFieldDto.Nested?.Count > 0) { rootField.Nested = new List <UpsertSchemaNestedField>(); foreach (var nestedFieldDto in rootFieldDto.Nested) { var nestedProps = nestedFieldDto?.Properties.ToProperties(); var nestedField = new UpsertSchemaNestedField { Properties = nestedProps }; SimpleMapper.Map(nestedFieldDto, nestedField); rootField.Nested.Add(nestedField); } } command.Fields.Add(rootField); } } return(command); }
private static void ValidateNestedField(UpsertSchemaNestedField nestedField, string prefix, AddValidation e) { if (nestedField == null) { e(Not.Defined("Field"), prefix); } else { if (nestedField.Properties is ArrayFieldProperties) { e(T.Get("schemas.onylArraysInRoot"), $"{prefix}.{nameof(nestedField.Properties)}"); } ValidateField(nestedField, prefix, e); } }
private static void ValidateNestedField(UpsertSchemaNestedField nestedField, string prefix, AddValidation e) { if (nestedField == null) { e(Not.Defined("Field"), prefix); } else { if (nestedField.Properties is ArrayFieldProperties) { e("Nested field cannot be array fields.", $"{prefix}.{nameof(nestedField.Properties)}"); } ValidateField(nestedField, prefix, e); } }