The IsValid()
method on the work item only validates that the fields on the work item is correct, it does not check whether or not the work item has changed elsewhere. There is a flag on the work item object that is called IsDirty
which checks to see whether or not the work item has changed since the last save.
As a side note, the fields you display as an error message are only fields that do not adhere to the rules of the work item type definition (i.e. a value of a field that is outside of its defined AllowedValues
). This should be checked, but a check for whether, or not, it has changed since the last save should display a different error.
Here's a link to MSDN for the WorkItem
class: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.workitemtracking.client.workitem(v=vs.110).aspx
EDIT
The IsDirty
flag will pick up whether, or not, the work item has been modified locally. Instead, the way to check for server-side saves is to try to merge while saving the work item.
workItem.Save(SaveFlags.MergeAll);
The IsValid
flag is for local changes, not server changes. Saving the work item with the SaveFlags.MergAll
option will do the check, and throw the exception if the work item has been saved on the server side.