private Workflow GetWorkflow(Workflow request) { var id = request?.Id; Workflow ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Workflow>(currentUser, "Workflow", request.Select); DocEntityWorkflow entity = null; if (id.HasValue) { entity = DocEntityWorkflow.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Workflow found for Id {id.Value}"); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route."); } ret = entity?.ToDto(); return(ret); }
public Workflow Post(WorkflowCopy request) { Workflow ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityWorkflow.Get(request?.Id); if (null == entity) { throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed."); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } var pBindings = entity.Bindings.ToList(); var pData = entity.Data; var pDescription = entity.Description; if (!DocTools.IsNullOrEmpty(pDescription)) { pDescription += " (Copy)"; } var pDocuments = entity.Documents.ToList(); var pDocumentSet = entity.DocumentSet; var pName = entity.Name; if (!DocTools.IsNullOrEmpty(pName)) { pName += " (Copy)"; } var pOwner = entity.Owner; var pScopes = entity.Scopes.ToList(); var pStatus = entity.Status; var pTasks = entity.Tasks.ToList(); var pType = entity.Type; var pUser = entity.User; var pVariables = entity.Variables.ToList(); var pWorkflows = entity.Workflows.ToList(); var copy = new DocEntityWorkflow(ssn) { Hash = Guid.NewGuid() , Data = pData , Description = pDescription , DocumentSet = pDocumentSet , Name = pName , Owner = pOwner , Status = pStatus , Type = pType , User = pUser }; foreach (var item in pBindings) { entity.Bindings.Add(item); } foreach (var item in pDocuments) { entity.Documents.Add(item); } foreach (var item in pScopes) { entity.Scopes.Add(item); } foreach (var item in pTasks) { entity.Tasks.Add(item); } foreach (var item in pVariables) { entity.Variables.Add(item); } foreach (var item in pWorkflows) { entity.Workflows.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }