public async Task <IHttpActionResult> PostWorkflow(Workflow workflow) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } workflowService.Add(workflow); workflowService.CommitAsync(); return(CreatedAtRoute("DefaultApi", new { id = workflow.WorkflowId }, workflow)); }
/// <summary> /// Adds a workflow to the underlying repository /// </summary> /// <param name="community">The community that will be associated with the workflow</param> public void AddWorkflow(Community community) { // Define the transitions for workflow: // Pending -> (Accept) -> Accepted // | |-- (Approve) -> Approved // | `- (Reject) -> Rejected // `---> (Ignore) -> Rejected var workflowTransitions = new List <WorkflowTransition> { new WorkflowTransition(new WorkflowState("Pending"), new WorkflowState("Accepted"), new WorkflowAction("Accept")), new WorkflowTransition(new WorkflowState("Pending"), new WorkflowState("Rejected"), new WorkflowAction("Ignore")), new WorkflowTransition(new WorkflowState("Accepted"), new WorkflowState("Approved"), new WorkflowAction("Approve")), new WorkflowTransition(new WorkflowState("Accepted"), new WorkflowState("Rejected"), new WorkflowAction("Reject")) }; // Save the new workflow with custom extension data which // identifies the community it is intended to be associated with. var membershipWorkflow = new Workflow( "Membership: " + community.Name, workflowTransitions, new WorkflowState("Pending") ); var workflowExtension = new MembershipModeration { Group = community.Id }; if (membershipWorkflow != null) { try { _workflowService.Add(membershipWorkflow, workflowExtension); } catch (SocialAuthenticationException ex) { throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex); } catch (MaximumDataSizeExceededException ex) { throw new SocialRepositoryException( "The application request was deemed too large for Episerver Social.", ex); } catch (SocialCommunicationException ex) { throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex); } catch (SocialException ex) { throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex); } } }