/// <summary>
        /// Constructor to get all user and initialize the services
        /// </summary>
        public WorkflowOrganizationUnitAssignmentViewModel(WorkflowOrganizationUnitAssignment workflowOrganizationUnit, IViewModelBase parent)
        {
            Parent      = parent;
            Model       = workflowOrganizationUnit;
            userService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IUserService>();
            workflowOrganizationUnitService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IWorkflowOrganizationUnitService>();

            if (Parent is DocumentWorkflowConfigurationViewModel viewModel)
            {
                Header = workflowOrganizationUnitService.Get(workflowOrganizationUnit.WorkflowOrganisationUnitId).DisplayName;
                remove = new RelayCommand(o => viewModel.RemoveItem(this));
            }

            //Todo:Expect the user that are already loaded in
            allUsers = new ObservableCollection <UserViewModel>((Parent as DocumentWorkflowConfigurationViewModel).Users.Select(x => new UserViewModel(x, new WorkflowOrganizationUnitUserAssignment(), this)
            {
            }));
            assignedUsers = new ObservableCollection <UserViewModel>(Model.Users.GetAsObservableCollection().Select(x => new UserViewModel(userService.GetById(x.UserId), x, this)));
            var list = workflowOrganizationUnit.Users.GetItems();

            //TODO: Improve because of performance issues, maybe?
            allUsers = new ObservableCollection <UserViewModel>(allUsers.Where(allUser => !assignedUsers.Any(assignedUser => assignedUser.Model.UserId == allUser.Model.UserId)));

            userSource                = new CollectionViewSource();
            userAssignedSource        = new CollectionViewSource();
            userSource.Source         = AllUsers;
            userAssignedSource.Source = AssignedUsers;

            userSource.Filter         += UserSource_Filter;
            userAssignedSource.Filter += UserAssignedSource_Filter;
            userSource.SortDescriptions.Add(new System.ComponentModel.SortDescription {
                Direction = System.ComponentModel.ListSortDirection.Ascending, PropertyName = "Name"
            });
            userAssignedSource.SortDescriptions.Add(new System.ComponentModel.SortDescription {
                Direction = System.ComponentModel.ListSortDirection.Ascending, PropertyName = "Name"
            });

            CollectionNotifyPropertyChanged(assignedUsers, workflowOrganizationUnit.Users, (x) => x.Model);
            RaisePropertyChanged(nameof(AllUsers));
            RaisePropertyChanged(nameof(AssignedUsers));
        }
Exemple #2
0
        /// <summary>
        /// Saves the assignments
        /// </summary>
        public void PrepareSaving()
        {
            var workflowConfigurationGuid = Model.Guid;

            foreach (var tab in assignments)
            {
                var organizationUnitAssignment = new WorkflowOrganizationUnitAssignment
                {
                    WorkflowId = workflowConfigurationGuid,
                    WorkflowOrganisationUnitId = tab.Model.Guid
                };

                //Assigns and saves the user to a worklfow organization unit
                foreach (var userViewModel in tab.AssignedUsers)
                {
                    var userAssignment = new WorkflowOrganizationUnitUserAssignment {
                    };
                    userAssignment.UserId = (int)userViewModel.Id;
                    userAssignment.WorkflowOrganzitionAssignmentId = tab.Model.Guid;
                }
            }
        }