public bool Delete(DocumentWorkflowAssignment obj) => repository.Delete(obj);
public bool Save(DocumentWorkflowAssignment obj) => repository.Save(obj);
/// <summary> /// Save file structure to database /// </summary> /// <param name="obj">Object to save</param> /// <returns>True if successfull</returns> public bool Save(FileStructureDocumenPath obj) { var fileStructure = structureService.Get(obj.FileStructureGuid); obj.Path = ""; if (fileStructure != null) { var currentItem = fileStructure.Directories.FirstOrDefault(x => x.Id == obj.DirectoryGuid); while (currentItem != null) { obj.Path = obj.Path.Insert(0, $"/{currentItem.Name}"); if (currentItem.Parent != null) { currentItem = currentItem.Parent; } else { currentItem = null; break; } } } var result = repository.Save(obj); // Path has changed if (obj.PreviousPath != obj.Path || obj.PreviousWorkflowState != obj.WorkflowState) { try { fileStructureDocumentPathTrackingRepository.Save(new FileStructureDocumenPathTracking { Id = Guid.NewGuid(), DirectoryGuid = obj.DirectoryGuid, DocumentGuid = obj.DocumentGuid, WorkflowState = obj.WorkflowState, FileStructureGuid = obj.FileStructureGuid, FileStructureHash = obj.FileStructureHash, IsProtectedPath = obj.IsProtectedPath, Path = obj.Path ?? "", StorageHash = obj.StorageHash, UserId = sessionService.CurrentSession.UserId, PreviousPath = obj.PreviousPath ?? "" }); if (obj.WorkflowId.HasValue) { var workflowId = obj.WorkflowId.Value; var workflow = documentWorkflowConfigurationService.Get(workflowId); if (workflow == null) { throw new Exception($"Could not find workflow: {workflowId}"); } var stateProvider = unityContainer.Resolve <IDocumentWorkflowStateProvider>(workflow.StateProviderName); var state = stateProvider.ResolveDocumentWorkflowState(obj.DocumentGuid, workflowId); if (state == null) { throw new Exception($"Could not resolve initial state for document: {obj.DocumentGuid}"); } if (!documentWorkflowAssignmentService.Exists(obj.DocumentGuid, workflowId)) { var assignment = new DocumentWorkflowAssignment { DocumentId = obj.DocumentGuid, WorkflowId = workflowId, StateId = state.Guid }; documentWorkflowAssignmentService.Save(assignment); } else { documentWorkflowAssignmentService.SetState(obj.DocumentGuid, workflowId, state.Guid); } } } catch (Exception ex) { Log.LogManagerInstance.Instance.Error($"Could not write file structure path tracking: Document id: {obj.DocumentGuid}", ex); } } return(result); }