@@ -231,22 +231,8 @@ public void EnsureFieldsOnStateChange(WiRevision rev, WorkItem wi)
231231
232232            if  ( rev . Index  !=  0  &&  rev . Fields . HasAnyByRefName ( WiFieldReference . State ) ) 
233233            { 
234-                 var  wiState  =  wi . Fields [ WiFieldReference . State ] . ToString ( )  ??  string . Empty ; 
235-                 var  revState  =  rev . Fields . GetFieldValueOrDefault < string > ( WiFieldReference . State )  ??  string . Empty ; 
236-                 if  ( wiState . Equals ( "Done" ,  StringComparison . InvariantCultureIgnoreCase )  &&  revState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase ) ) 
237-                 { 
238-                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedDate ,  Value  =  null  } ) ; 
239-                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedBy ,  Value  =  null  } ) ; 
240- 
241-                 } 
242-                 if  ( ! wiState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase )  &&  revState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase ) ) 
243-                 { 
244-                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ActivatedDate ,  Value  =  null  } ) ; 
245-                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ActivatedBy ,  Value  =  null  } ) ; 
246-                 } 
247- 
248-                 if  ( revState . Equals ( "Done" ,  StringComparison . InvariantCultureIgnoreCase )  &&  ! rev . Fields . HasAnyByRefName ( WiFieldReference . ClosedBy ) ) 
249-                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedBy ,  Value  =  rev . Author  } ) ; 
234+                 CorrectClosedByAndClosedDate ( rev ,  wi ) ; 
235+                 CorrectActivatedByAndActivatedDate ( rev ,  wi ) ; 
250236            } 
251237        } 
252238
@@ -575,6 +561,38 @@ private void CorrectImagePath(WorkItem wi, WiItem wiItem, WiRevision rev, ref st
575561            } 
576562        } 
577563
564+         private  void  CorrectClosedByAndClosedDate ( WiRevision  rev ,  WorkItem  wi ) 
565+         { 
566+             var  wiState  =  wi . Fields [ WiFieldReference . State ] . ToString ( )  ??  string . Empty ; 
567+             var  revState  =  rev . Fields . GetFieldValueOrDefault < string > ( WiFieldReference . State )  ??  string . Empty ; 
568+ 
569+             if  ( wiState . Equals ( "Done" ,  StringComparison . InvariantCultureIgnoreCase )  &&  revState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase ) ) 
570+             { 
571+                 rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedDate ,  Value  =  null  } ) ; 
572+                 rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedBy ,  Value  =  null  } ) ; 
573+             } 
574+ 
575+             if  ( revState . Equals ( "Done" ,  StringComparison . InvariantCultureIgnoreCase ) ) 
576+             { 
577+                 if  ( ! rev . Fields . HasAnyByRefName ( WiFieldReference . ClosedDate ) ) 
578+                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedDate ,  Value  =  rev . Time  } ) ; 
579+ 
580+                 if  ( ! rev . Fields . HasAnyByRefName ( WiFieldReference . ClosedBy ) ) 
581+                     rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ClosedBy ,  Value  =  rev . Author  } ) ; 
582+             } 
583+         } 
584+         private  void  CorrectActivatedByAndActivatedDate ( WiRevision  rev ,  WorkItem  wi ) 
585+         { 
586+             var  wiState  =  wi . Fields [ WiFieldReference . State ] . ToString ( )  ??  string . Empty ; 
587+             var  revState  =  rev . Fields . GetFieldValueOrDefault < string > ( WiFieldReference . State )  ??  string . Empty ; 
588+ 
589+             if  ( ! wiState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase )  &&  revState . Equals ( "New" ,  StringComparison . InvariantCultureIgnoreCase ) ) 
590+             { 
591+                 rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ActivatedDate ,  Value  =  null  } ) ; 
592+                 rev . Fields . Add ( new  WiField ( )  {  ReferenceName  =  WiFieldReference . ActivatedBy ,  Value  =  null  } ) ; 
593+             } 
594+         } 
595+ 
578596        private  void  AddSingleAttachmentToWorkItemAndSave ( WiAttachment  att ,  WorkItem  wi ) 
579597        { 
580598            // Upload attachment 
@@ -805,4 +823,4 @@ private int GetRelatedWorkItemIdFromLink(WorkItemRelation link)
805823            return  int . Parse ( link . Url . Split ( '/' ) . Last ( ) ) ; 
806824        } 
807825    } 
808- } 
826+ } 
0 commit comments