Approval approval;
IApprovalEngine approvalEngine;
await approvalEngine.AbortAsync(approval.ID, "user");
Making a decision
Use the engine to decide to approve or reject a step or the whole approval. There is a possibility to add an optional comment to explain the reason for the decision. If the decision finishes the approval (approves the last step or rejects a step), this comment is saved on the approval as CompletedComment.
Approval approval;
IApprovalEngine approvalEngine;
// Approve a step if user is part of the current definition step
await approvalEngine.ApproveAsync(approval.ID, "user", 1, ApprovalDecisionScope.Step);
// Reject a step if user is part of the current definition step, adding a comment
await approvalEngine.RejectAsync(approval.ID, "user", 1, ApprovalDecisionScope.Step, "This is why I did it");
// Force approve a step whether the user is part of the current definition step or not
await approvalEngine.ApproveAsync(approval.ID, "user", 1, ApprovalDecisionScope.ForceStep);
// Force approve the whole approval
await approvalEngine.ApproveAsync(approval.ID, "user", 1, ApprovalDecisionScope.Force);
There are also a number of more explicitly named extension methods to the engine that can be used, for example ApproveStepAsync and ForceApproveAsync.
Listing approvals
Use the GetAsync / GetItemsAsync methods on IApprovalRepository to get specific approvals using ID or ContentReference:
using EPiServer.Approvals.ContentApprovals;
ContentReference contentLink;
IApprovalRepository approvalRepository;
var approval = await approvalRepository.GetAsync(contentLink);
The ListAsync method takes an ApprovalQuery / ContentApprovalQuery object which searches the approvals based on the specified query-data and returns a filtered list. This list can be paged.
This example gets all approvals in review for a user based on a specific definition.
using EPiServer.Approvals.ContentApprovals;
ContentApprovalDefinition definition;
IApprovalRepository approvalRepository;
var approvals = await approvalRepository.ListAsync(new ContentApprovalQuery
{
Username = "user",
Status = ApprovalStatus.InReview,
DefinitionID = definition.ID
});
This example list decisions made for an approval:
Approval approval;
IApprovalRepository approvalRepository;
var decisions = await approvalRepository.ListDecisionsAsync(approval.ID);