' "Get a list of suppressed and unsuppressed messages"
' Your variable names tell me what these are, as well as having a simple predicate. Maybe it could be argues for two full blown methods:
' GetSuppressedMessages(bvMessages) and GetUnsuppressedMessage(bvMessage). Meh, I wouldn't feel that to be 100% necessary.
Dim unsuppressedMessages As List(Of BatchValidationMessagesUIModel) = bvMessages.Where(Function(m) m.SUPPRESSED.Value = False).ToList
Dim suppressedMessages As List(Of BatchValidationMessagesUIModel) = bvMessages.Where(Function(m) m.SUPPRESSED.Value = True).ToList
Dim errorAnnotations = annotations.Value.Where(Function(a) a.Text.Value = "Record contains custom validation error(s).").ToList
Dim warningAnnotations = annotations.Value.Where(Function(a) a.Text.Value = "Record contains suppressed custom validation error(s).").ToList
annotations.Visible = True
' "If there are unsuppressed messages, ..."
' Well, how about writing the code exactly saying that, instead of obscuring it with counting and then
' comparing that count with some other value?
If unsuppressedMessages.Any Then
' "..., add to the annotations (the actual error will be a part of the system messages, which will prevent it from committing"
' The part in brackets might fall in to the "comment why its the non-obvious way" part of my reason for commenting
' The "add to the annotations part, however....
AddToAnnotations(unsuppressedMessages)
End If
' "If there are suppressed messages, ..."
' Again, let's write our condition so it reads how you want to write the comment
If suppressedMessages.Any Then
' "...add to the annotations - should be a warning, so that it can still commit"
' Sounds like we need to note that this is added as a warning, so I'll include that in the method name
' Note that I've included the AndAlso check in this method, as it felt part of that logic -
' another point about code that doesn't need comment is that you need to separate your concerns more carefully
AddWarningForSuppressedMessage()
End If
' ...
Private Sub AddToAnnotations(unsuppressedMessages As List(Of Blah)
' "If there isn't already a current notice about custom validations, then add it"
' So, we want to ensure that there's a custom validation notice? Okay...
EnsureCustomValidationNotice()
' "Add the validaiton messages"
' What part of that isn't explained in the code?
For Each msg As BatchValidationMessagesUIModel In unsuppressedMessages
AddRowAnnotation(currentModel, AnnotationCategory.Unknown, msg.MESSAGETEXT.Value, False, BatchMessageType.GeneralError)
Next
End Sub
Private Sub EnsureCustomValidationNotice
If errorAnnotations.Count = 0 Then
AddRowAnnotation(currentModel, AnnotationCategory.Unknown, "Record contains custom validation error(s).", False, BatchMessageType.GeneralError)
End If
End Sub
Private Sub AddWarningForSuppressedMessage
If Not warningAnnotations.Any Then
AddRowAnnotation(currentModel, AnnotationCategory.Unknown, "Record contains suppressed custom validation error(s).", False, BatchMessageType.GeneralError)
End If
End Sub