Improve validation

This commit is contained in:
Jonathan Jenne 2021-11-18 13:31:14 +01:00
parent 3b07002c28
commit 3760453d82
2 changed files with 67 additions and 32 deletions

View File

@ -153,12 +153,13 @@ Namespace Documents
Where(Function(t) t.Name = oTopLevelElement.Name). Where(Function(t) t.Name = oTopLevelElement.Name).
FirstOrDefault() FirstOrDefault()
For Each oSubElement As XElement In oSubElements For Each oColumn In oTable.Columns
Dim oSchemaField = oTable.Columns. Dim oSubElement = oSubElements.
Where(Function(c) c.Name = oSubElement.Name). Where(Function(e) e.Name = oColumn.Name).
SingleOrDefault() SingleOrDefault()
Dim oRequired = oSchemaField.IsRequired If oSubElement IsNot Nothing Then
Dim oRequired = oColumn.IsRequired
Dim oValue = oSubElement.Value.Trim() Dim oValue = oSubElement.Value.Trim()
' TODO: Needed when we have time for date times ' TODO: Needed when we have time for date times
@ -170,20 +171,10 @@ Namespace Documents
oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With { oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
.Original = oValue, .Original = oValue,
.Final = oValue, .Final = oValue,
.DataType = oSchemaField.DataType, .DataType = oColumn.DataType,
.Required = oRequired .Required = oRequired
}) })
Else
Next
' All fields in the schema are generated,
' only creating the ones with values leads to wrong visual cues when asking for
' docs/rows/fields with errors
For Each oColumn In oTable.Columns
If oFields.ContainsKey(oColumn.Name) Then
Continue For
End If
Dim oColumnError = DocumentRow.FieldError.None Dim oColumnError = DocumentRow.FieldError.None
If oColumn.Config?.IsRequired Then If oColumn.Config?.IsRequired Then
oColumnError = DocumentRow.FieldError.MissingValue oColumnError = DocumentRow.FieldError.MissingValue
@ -192,8 +183,50 @@ Namespace Documents
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With { oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
.[Error] = oColumnError .[Error] = oColumnError
}) })
End If
Next Next
'For Each oSubElement As XElement In oSubElements
' Dim oSchemaField = oTable.Columns.
' Where(Function(c) c.Name = oSubElement.Name).
' SingleOrDefault()
' Dim oRequired = oSchemaField.IsRequired
' Dim oValue = oSubElement.Value.Trim()
' ' TODO: Needed when we have time for date times
' 'If oSchemaField.DataType = Constants.ColumnType.Date Then
' ' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture)
' ' oValue = oDate.ToString("d")
' 'End If
' oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
' .Original = oValue,
' .Final = oValue,
' .DataType = oSchemaField.DataType,
' .Required = oRequired
' })
'Next
'' All fields in the schema are generated,
'' only creating the ones with values leads to wrong visual cues when asking for
'' docs/rows/fields with errors
'For Each oColumn In oTable.Columns
' If oFields.ContainsKey(oColumn.Name) Then
' Continue For
' End If
' Dim oColumnError = DocumentRow.FieldError.None
' If oColumn.Config?.IsRequired Then
' oColumnError = DocumentRow.FieldError.MissingValue
' End If
' oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
' .[Error] = oColumnError
' })
'Next
' Create a DocumentRow object for each Top Level Element ' Create a DocumentRow object for each Top Level Element
Dim oRow = New DocumentRow With { Dim oRow = New DocumentRow With {
.SortKey = oSortKey, .SortKey = oSortKey,

View File

@ -60,7 +60,9 @@
Public ReadOnly Property HasError As Boolean Public ReadOnly Property HasError As Boolean
Get Get
Return [Error] <> FieldError.None Or (Required = True And Final = String.Empty) Return Required = True And (
[Error] <> FieldError.None Or Final = String.Empty
)
End Get End Get
End Property End Property