예제 #1
0
        private void btnDelProfile_Click(object sender, RoutedEventArgs e)
        {
            var serviceViewModel = cbProfile.SelectedItem as ProfileViewModel;

            if (MessageBox.Show($"Deseja realmente remover o perfil: {serviceViewModel.Name} do agent?", "Atenção", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                _agentsService.DeleteProfile(_id, serviceViewModel.ProfileViewItem.FirstOrDefault().ProfileIdentifier).ContinueWith(task =>
                {
                    if (task.Result.IsSuccess)
                    {
                        MessageBox.Show($"Removido com sucesso", "Sucesso", MessageBoxButton.OK, MessageBoxImage.Information);

                        var list = cbProfile.ItemsSource as List <ProfileViewModel>;

                        list.Remove(serviceViewModel);

                        if (serviceViewModel.Name.Equals(_agentDetail.ProfileName))
                        {
                            cbProfile.SelectedIndex  = 0;
                            _agentDetail.ProfileName = cbProfile.Text;
                            lblProfile.Text          = _agentDetail.ProfileName;
                        }
                    }
                    else
                    {
                        MessageBox.Show($"Falha na tentativa de remoção, contate o administrador", "Falha", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }