Example #1
0
        public override void Delete()
        {
            if (CurrentUserViewModel == null)
            {
                ModernDialog.ShowMessage("请选择一个用户。", "操作警告", MessageBoxButton.OK);
                return;
            }

            if (ModernDialog.ShowMessage("确定删除当前用户?", "删除警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (_userDataAccessor.Delete(Mapper.Map <User>(CurrentUserViewModel)))
                {
                    var currentIndex = UserViewModels.IndexOf(CurrentUserViewModel);
                    UserViewModels.Remove(CurrentUserViewModel);

                    if (currentIndex > 0)
                    {
                        CurrentUserViewModel = UserViewModels[currentIndex - 1];
                    }
                    else if (UserViewModels.Count > 0)
                    {
                        CurrentUserViewModel = UserViewModels[0];
                    }
                }
            }
        }
 private void Rollback()
 {
     if (UserViewModel != null)
     {
         if (Action == ViewModelAction.Add)
         {
             UserViewModels.Remove(UserViewModel);
         }
         else
         {
             Mapper.Map(_userDataAccessor.GetByKey(UserViewModel.Id), UserViewModel);
         }
     }
 }
Example #3
0
        private void MoveUser()
        {
            try
            {
                if (SelectedUserViewModel == null)
                {
                    Messenger.Default.Send(new NotificationMessage("请先选择人员!"), Tokens.UserPage_ShowNotification);
                    return;
                }

                var coreModel = _userRepo.GetByKey(SelectedUserViewModel.UserID);
                var viewModel = new MoveUserViewModel(coreModel);
                Messenger.Default.Send(new OpenWindowMessage()
                {
                    DataContext = viewModel,
                    WindowType  = "MoveUserView",
                }, Tokens.OpenUserView);

                if (viewModel.ViewModelAttachment.LastOperationSuccess)
                {
                    if (viewModel.ViewModelAttachment.CoreModel.DepartmentID != SelectedDepartmentId)
                    {
                        UserViewModels.Remove(SelectedUserViewModel);

                        var coreUser = CurrentDepartmentUsers.FirstOrDefault(x => x.UserID == coreModel.UserID);
                        CurrentDepartmentUsers.Remove(coreUser);
                    }
                    else
                    {
                        var index = UserViewModels.IndexOf(SelectedUserViewModel);
                        UserViewModels[index] = new UserViewModel(viewModel.ViewModelAttachment.CoreModel);

                        var coreUser = CurrentDepartmentUsers.FirstOrDefault(x => x.UserID == coreModel.UserID);
                        CurrentDepartmentUsers.Remove(coreUser);
                        CurrentDepartmentUsers.Add(viewModel.ViewModelAttachment.CoreModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Example #4
0
        private void ConfirmDeleteUser()
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                string message = "";
                try
                {
                    _userRepo.Delete(SelectedUserViewModel.CurrentUser.UserID);
                    message = "删除人员成功!";

                    UserViewModels.Remove(SelectedUserViewModel);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    message = "删除人员失败!";
                }
                Messenger.Default.Send(new NotificationMessage(message), Tokens.UserPage_ShowNotification);
            });
        }