Exemple #1
0
        public async Task <ActionResult> Index(
            ContentApprovalsManagerPage currentPage,
            string task, int?stepIndex, string user, string decision)
        {
            var viewmodel = new ContentApprovalsManagerViewModel(currentPage);

            if (!string.IsNullOrWhiteSpace(task))
            {
                switch (task)
                {
                case "createDefinition":

                    var all     = new[] { CultureInfo.InvariantCulture };
                    var english = new[] { CultureInfo.GetCultureInfo("en") };
                    var swedish = new[] { CultureInfo.GetCultureInfo("sv") };

                    var def = new ContentApprovalDefinition
                    {
                        ContentLink = ContentReference.StartPage,
                        Steps       = new List <ApprovalDefinitionStep>
                        {
                            new ApprovalDefinitionStep(
                                "Alice reviews English, Bob reviews Swedish", new[]
                            {
                                new ApprovalDefinitionReviewer(userName1, english),
                                new ApprovalDefinitionReviewer(userName2, swedish),
                            }),
                            new ApprovalDefinitionStep(
                                "Editors (Eve or Bob) reviews all languages", new[]
                            {
                                new ApprovalDefinitionReviewer(editors, all, ApprovalDefinitionReviewerType.Role)
                            })
                        },
                        RequireCommentOnReject = true
                    };

                    await repoDefinitions.SaveAsync(def);

                    break;

                case "modifyStart":

                    var approvalToDelete = await repoApprovals.GetAsync(ContentReference.StartPage);

                    if (approvalToDelete != null)
                    {
                        await repoApprovals.DeleteAsync(approvalToDelete.ID);
                    }

                    var start = repoContent.Get <StartPage>(ContentReference.StartPage)
                                .CreateWritableClone() as StartPage;

                    start.Name += "X";

                    repoContent.Save(content: start,
                                     action: SaveAction.RequestApproval,
                                     access: AccessLevel.NoAccess);

                    break;

                case "processStep":

                    var approval = await repoApprovals.GetAsync(ContentReference.StartPage);

                    if (approval.ActiveStepIndex <= stepIndex)
                    {
                        if (decision == "Approve")
                        {
                            await engine.ApproveStepAsync(
                                id : approval.ID,
                                username : user,
                                stepIndex : stepIndex.Value,
                                comment : "I approve: the page looks great!");
                        }
                        else
                        {
                            await engine.RejectStepAsync(
                                id : approval.ID,
                                username : user,
                                stepIndex : stepIndex.Value,
                                comment : "I decline: the page looks horrible!");
                        }
                    }
                    break;

                case "deleteApprovals":

                    var list = await repoApprovals.ListAsync(new ApprovalQuery());

                    foreach (var item in list)
                    {
                        await repoApprovals.DeleteAsync(item.ID);
                    }

                    break;
                }
            }

            // GetAsync(ContentReference) extension methods need
            // using EPiServer.Approvals.ContentApprovals
            viewmodel.ApprovalDefinition = await repoDefinitions.GetAsync(ContentReference.StartPage);

            viewmodel.Approval = await repoApprovals.GetAsync(ContentReference.StartPage);

            return(View("~/Features/ContentApprovals/ContentApprovalsManager.cshtml", viewmodel));
        }
Exemple #2
0
        public async Task <ActionResult> Index(
            ContentApprovalsManagerPage currentPage,
            string task, int?stepIndex, string user, string decision)
        {
            var viewmodel = new ContentApprovalsManagerPageViewModel(currentPage);

            if (!string.IsNullOrWhiteSpace(task))
            {
                switch (task)
                {
                case "createDefinition":

                    var langEN = new[] { CultureInfo.GetCultureInfo("en") };
                    var langSV = new[] { CultureInfo.GetCultureInfo("sv") };

                    var def = new ContentApprovalDefinition
                    {
                        ContentLink = ContentReference.StartPage,
                        Steps       = new List <ApprovalDefinitionStep>
                        {
                            new ApprovalDefinitionStep(
                                "Alice reviews English, Bob reviews Swedish", new[]
                            {
                                new ApprovalDefinitionReviewer(userName1, langEN),
                                new ApprovalDefinitionReviewer(userName2, langSV),
                            }),
                            new ApprovalDefinitionStep(
                                "Eve reviews both languages", new[]
                            {
                                new ApprovalDefinitionReviewer(userName3, langEN.Union(langSV))
                            })
                        },
                        RequireCommentOnReject = true
                    };

                    await repoDefinitions.SaveAsync(def);

                    break;

                case "modifyStart":

                    var start = repoContent.Get <StartPage>(ContentReference.StartPage)
                                .CreateWritableClone() as StartPage;

                    start.Name += "X";

                    repoContent.Save(content: start,
                                     action: SaveAction.RequestApproval,
                                     access: AccessLevel.NoAccess);

                    break;

                case "processStep":

                    var approval = await repoApprovals.GetAsync(ContentReference.StartPage);

                    if (decision == "Approve")
                    {
                        await engine.ApproveStepAsync(
                            id : approval.ID,
                            username : user,
                            stepIndex : stepIndex.Value,
                            comment : "I approve: the page looks great!");
                    }
                    else
                    {
                        await engine.RejectStepAsync(
                            id : approval.ID,
                            username : user,
                            stepIndex : stepIndex.Value,
                            comment : "I decline: the page looks horrible!");
                    }
                    break;
                }
            }

            // GetAsync(ContentReference) extension methods need
            // using EPiServer.Approvals.ContentApprovals
            viewmodel.ApprovalDefinition = await repoDefinitions.GetAsync(ContentReference.StartPage);

            viewmodel.Approval = await repoApprovals.GetAsync(ContentReference.StartPage);

            return(View(viewmodel));
        }