Пример #1
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure?", "Accept Confirmation", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                var selectedItem = (User)UsersListView.SelectedItem;
                if (selectedItem.Role == UserRole.Client)
                {
                    var clientToDelete = _clientBusinessComponent.GetByUserId(selectedItem.UserId);
                    _clientBusinessComponent.Delete(clientToDelete);
                    _usersList.Remove(selectedItem);
                    _clientBusinessComponent = _ninjectKernel.Get <IClientBusinessComponent>();
                }
                else
                {
                    if (selectedItem.Role == UserRole.Admin &&
                        _userBusinessComponent.GetAll().Count(x => x.Role == UserRole.Admin) <= 1)
                    {
                        MessageBox.Show("This is the last admin. Record cannot be deleted!");
                    }
                    else
                    {
                        _userBusinessComponent.Delete(selectedItem);
                        _usersList.Remove(selectedItem);
                        _userBusinessComponent = _ninjectKernel.Get <IUserBusinessComponent>();
                    }
                }
            }
        }