# TriggerManagement [C#]

This example shows how to retrive groups and triggers from specific manager, and ho to change the 'publish' status to 'unpublish'.

[C#]

       //Initialize the XAML object and retrieve group from server by login
       public TriggerManagement(string login, string password)
       {
           InitializeComponent();

           //Login and retrive group
           List<View_Group> listResult;
           sample.GetGroup(out listResult, login, password);

           //Bind group to TreeList
           treeGroup.ItemsSource = TreeNode.GetTreeNode(listResult);
       }

[C#]

       //Select group and retrive coresponding media trigger
       private void treeGroup_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
       {
           //Get Medias for selected group
           List<View_Media> listResult;
           sample.GetTrigger(out listResult, (treeGroup.SelectedItem as TreeNode).Id ?? 0);

           //Update media thumbnail path
           listResult.ForEach(x => x.ThumbnailPath = (x.ThumbnailPath != null) ? (GlobalParam.MEDIA_URL + x.ThumbnailPath) : "");

           //Bind group to List
           gridTrigger.ItemsSource = new ObservableCollection<View_Media>(listResult);
       }

[C#]

       //Select media
       private void gridTrigger_SelectionChanged(object sender, SelectionChangedEventArgs e)
       {
           if (gridTrigger.SelectedItem == null) return;

           //Display if the media as 'Published' or 'Unpublished'
           btnPublish.Content = (gridTrigger.SelectedItem as View_Media).FolderId == -3 ? "Unpublished" : "Published";
       }

[C#]

       //Published / Unpublished a media
       private void btnPublish_Click(object sender, RoutedEventArgs e)
       {
           //keep the media to publish
           View_Media trigger = gridTrigger.SelectedItem as View_Media;

           //change this folder id
           trigger.FolderId = trigger.FolderId == -3 ? -4 : -3;

           //Update the media
           sample.UpdateMedia(ref trigger);

           //Refresh the media collection
           gridTrigger_SelectionChanged(null, null);
       }