@@ -18,6 +18,7 @@ public partial class MainForm : Form
1818 private void LoadTagsForSelection ( )
1919 {
2020 _tags . Clear ( ) ;
21+ _originalTags . Clear ( ) ;
2122
2223 var selectedResources = _gvwResults . SelectedItems . Cast < Resource > ( ) . ToList ( ) ;
2324
@@ -36,6 +37,7 @@ private void LoadTagsForSelection()
3637 foreach ( var kvp in res . CombinedTags . OrderBy ( k => k . Key ) )
3738 {
3839 _tags . Add ( new TagEntry { Key = kvp . Key , Value = kvp . Value } ) ;
40+ _originalTags [ kvp . Key ] = kvp . Value ;
3941 }
4042 }
4143 }
@@ -89,6 +91,7 @@ private void LoadTagsForSelection()
8991 foreach ( var kvp in commonTags . OrderBy ( k => k . Key ) )
9092 {
9193 _tags . Add ( new TagEntry { Key = kvp . Key , Value = kvp . Value } ) ;
94+ _originalTags [ kvp . Key ] = kvp . Value ;
9295 }
9396 }
9497 }
@@ -102,9 +105,16 @@ private async Task ApplyTagsAsync()
102105 var tagsToUpdate = _tags
103106 . Where ( t => ! string . IsNullOrWhiteSpace ( t . Key ) )
104107 . ToDictionary ( t => t . Key , t => t . Value ) ;
108+
109+ // Determine which tags were deleted by comparing original tags with current tags
110+ var currentTagKeys = tagsToUpdate . Keys . ToHashSet ( ) ;
111+ var tagsToRemove = _originalTags
112+ . Where ( kv => ! currentTagKeys . Contains ( kv . Key ) )
113+ . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
114+
105115 try
106116 {
107- var errors = await _azureService . UpdateTagsAsync ( selected , tagsToUpdate , null ) ;
117+ var errors = await _azureService . UpdateTagsAsync ( selected , tagsToUpdate , tagsToRemove ) ;
108118 if ( errors . Length > 0 )
109119 {
110120 MessageBox . Show ( this , string . Join ( "\n " , errors . Distinct ( ) ) , "Error" , MessageBoxButtons . OK , MessageBoxType . Error ) ;
@@ -115,6 +125,8 @@ private async Task ApplyTagsAsync()
115125 var tags = GetEntityTags ( res ) ;
116126 foreach ( var kv in tagsToUpdate )
117127 tags [ kv . Key ] = kv . Value ;
128+ foreach ( var kv in tagsToRemove )
129+ tags . Remove ( kv . Key ) ;
118130 res . CombinedTags = new Dictionary < string , string > ( tags ) ;
119131
120132 // Reload the row in the grid to reflect updated tags
0 commit comments