Example #1
0
        /// <summary>
        /// Sends the document to the target user id user.
        /// </summary>
        /// <param name="workflowOperation"></param>
        public void ForwardTo(WorkflowOperation workflowOperation)
        {
            var configuration  = documentWorkflowConfigurationService.Get(workflowOperation.WorkflowId);
            var accessProvider = unityContainer.Resolve <IDocumentWorkflowAccessProvider>(configuration.AccessProviderName);

            if (workflowOperation.OperationType == WorkflowOperationType.User)
            {
                // Add path to forwarded user
                var workflow = documentWorkflowUserService.Get(workflowOperation.TargetUserId);

                if (workflow == null)
                {
                    throw new DocumentWorkflowException("workflow is null");
                }

                var targetStructure = fileStructureService.GetByInstanceDataGuid(workflow.Guid);

                if (targetStructure == null)
                {
                    throw new DocumentWorkflowException("targetStructure is null");
                }

                var existingStructures = fileStructureDocumentPathService.GetByDocumentId(workflowOperation.DocumentId)
                                         .ToList();

                if (existingStructures == null)
                {
                    throw new DocumentWorkflowException("existingStructures is null");
                }

                var targetPath = existingStructures.FirstOrDefault(x => x.FileStructureGuid == targetStructure.Id);

                if (targetPath != null)
                {
                    var returnFolder = GetReturnDirectory(targetPath.FileStructureGuid, targetPath.WorkflowId.Value);
                    targetPath.DirectoryGuid = returnFolder.Id;
                    targetPath.WorkflowState = DocumentWorkflowStateType.InReview;
                }

                else
                {
                    var firstDirectory = FindWorkflowDirectory(
                        targetStructure,
                        workflowOperation.WorkflowId,
                        workflowOperation.DocumentId,
                        workflowOperation.TargetUserId);

                    if (firstDirectory == null)
                    {
                        throw new DocumentWorkflowException("existingStructures is null");
                    }

                    targetPath = new FileStructureDocumenPath
                    {
                        DirectoryGuid     = firstDirectory.Id,
                        FileStructureGuid = targetStructure.Id,
                        Id              = Guid.NewGuid(),
                        DocumentGuid    = workflowOperation.DocumentId,
                        WorkflowId      = workflowOperation.WorkflowId,
                        IsProtectedPath = false,
                        WorkflowState   = DocumentWorkflowStateType.InReview
                    };
                }

                var tracker = new DocumentWorkflowTracker
                {
                    ActionName     = DocumentWorkflowStateType.Forwarded,
                    CreateDateTime = DateTime.Now,
                    DocumentId     = targetPath.DocumentGuid,
                    TargetUserId   = workflowOperation.TargetUserId,
                    UserId         = workflowOperation.UserId
                };

                documentWorkflowTrackerService.Save(tracker);
                fileStructureDocumentPathService.Save(targetPath);

                if (accessProvider != null)
                {
                    accessProvider.SetUserAccess(workflowOperation.TargetUserId, workflowOperation.DocumentId, targetPath.Id, targetStructure.Id, configuration);
                }
            }
            else
            {
                SaveWorkflowOrganizationUnitAssignment(workflowOperation, configuration.StateProviderName);
                TrackChanges(workflowOperation, DocumentWorkflowStateType.Forwarded);
                if (accessProvider != null && workflowOperation.WorkflowOrganizationId.HasValue)
                {
                    accessProvider.SetOrganizationUnitAcess(workflowOperation.WorkflowOrganizationId.Value, workflowOperation.DocumentId, configuration);
                }
            }

            var path = fileStructureDocumentPathService.Get(workflowOperation.DocumentPath);

            path.WorkflowState = DocumentWorkflowStateType.Completed;
            fileStructureDocumentPathService.Save(path);

            flowEventService.InvokeEvent("DocumentForwarded", workflowOperation.Guid, workflowOperation, workflowOperation.UserId);
        }
        /// <summary>
        /// Initialize viewmodel
        /// </summary>
        /// <param name="documentId">Document id</param>
        public DocumentPathOverViewViewModel(Guid documentId)
        {
            this.documentId = documentId;

            documentPathService  = ServiceLocator.Current.GetInstance <IFileStructureDocumentPathService>();
            fileStructureService = ServiceLocator.Current.GetInstance <IFileStructureService>();
            directoryTypeService = ServiceLocator.Current.GetInstance <IDirectoryTypeService>();
            iconService          = ServiceLocator.Current.GetInstance <IIconService>();
            localizationService  = ServiceLocator.Current.GetInstance <ILocalizationService>();
            stackService         = ServiceLocator.Current.GetInstance <IStackService>();
            documentWorkflowAssignmentService = ServiceLocator.Current.GetInstance <IDocumentWorkflowAssignmentService>();

            removedPaths = new List <DocumentPathViewModel>();

            paths = new ObservableCollection <DocumentPathViewModel>();
            foreach (var path in documentPathService.GetByDocumentId(documentId))
            {
                var pathVM = new DocumentPathViewModel(path, fileStructureService, directoryTypeService, iconService, stackService)
                {
                    Parent = this
                };

                paths.Add(pathVM);
            }

            // Add new document path
            addDocumentPathCommand = new RelayCommand((p) =>
            {
                var newDocumentPath = SelectPath();

                if (newDocumentPath != null)
                {
                    if (CheckPathExists(newDocumentPath.Id, newDocumentPath.DirectoryGuid, newDocumentPath.FileStructureGuid))
                    {
                        MessageBox.Show(localizationService.Translate("filestructure_path_exists"), localizationService.Translate("filestructure_path_exists_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }

                    var newDocumentPathVM = new DocumentPathViewModel(newDocumentPath, fileStructureService, directoryTypeService, iconService, stackService)
                    {
                        Parent = this
                    };

                    Paths.Add(newDocumentPathVM);
                }
            });

            // Change document path
            changeDocumentPathCommand = new RelayCommand((p) =>
            {
                var selectedPath = p as DocumentPathViewModel;

                if (selectedPath.IsProtectedPath)
                {
                    MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                var fileStructure = fileStructureService.Get(selectedPath.Model.FileStructureGuid);


                var selectPathWindow = new FileStructureWindow();
                selectPathWindow.Initialize(fileStructure);
                selectPathWindow.IsInSelectMode = true;

                selectPathWindow.Loaded += (s, e) =>
                {
                    selectPathWindow.ViewModel.SelectedDirectory = selectPathWindow.ViewModel.RawDirectories.FirstOrDefault(x => x.Model.Id == selectedPath.Model.DirectoryGuid);
                };

                selectPathWindow.ShowDialog();

                if (selectPathWindow.SelectedDirectory != null)
                {
                    if (CheckPathExists(selectedPath.Model.Id, selectPathWindow.SelectedDirectory.Id, fileStructure.Id))
                    {
                        MessageBox.Show(localizationService.Translate("filestructure_path_exists"), localizationService.Translate("filestructure_path_exists_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }

                    selectedPath.Model.DirectoryGuid = selectPathWindow.SelectedDirectory.Id;
                    selectedPath.Model.WorkflowId    = selectPathWindow.SelectedDirectory.WorkflowId;
                    selectedPath.RefreshPath();
                }
            });

            // Remove document path
            removeDocumentPathCommand = new RelayCommand((p) =>
            {
                var selectedPath = p as DocumentPathViewModel;

                if (selectedPath.IsProtectedPath)
                {
                    MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                var messageBoxResult = MessageBox.Show(localizationService.Translate("filestructure_remove_path"), localizationService.Translate("filestructure_remove_path_title"), MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    removedPaths.Add(selectedPath);
                    paths.Remove(selectedPath);
                }
            });
        }