public async Task ApprovePost()
        {
            Post post = new Post("Test 1", "Lorem ipsum dolor amet....", "user");

            int postId = await _postsApprovalFlowService.AddPost(post);

            //Approve post
            post.UpdatePostStatus(Domain.Enum.PostStatusEnum.Published, "editor");
            await _postsApprovalFlowService.UpdatePost(post);
        }
コード例 #2
0
        public async Task<IActionResult> Post(int? id, PostInputModel model)
        {
            //Evaluate each submit type
            switch (model.SendType)
            {
                case "SAVE":
                    if (ModelState.IsValid)
                    {
                        Post post = null;
                        if (id.HasValue)
                        {
                            post = await _postsService.GetPost(id.Value);
                            post.Update(model.Title, model.Text);
                            await _postsApprovalFlowService.UpdatePost(post);
                            return RedirectToAction("Index");
                        }
                        else
                        {
                            post = new Post(model.Title, model.Text, User.Identity.Name);
                            int postId = await _postsApprovalFlowService.AddPost(post);

                            return RedirectToAction("Post", new { id = postId });
                        }
                    }
                    break;
                case "APPROVE":
                    if (id.HasValue)
                    {
                        var post = await _postsService.GetPost(id.Value);
                        post.UpdatePostStatus(Domain.Enum.PostStatusEnum.PendingPublishApproval, User.Identity.Name);
                        await _postsApprovalFlowService.UpdatePost(post);

                        return RedirectToAction("Index");
                    }
                    break;
                case "PUBLISH":
                    if (id.HasValue)
                    {
                        var post = await _postsService.GetPost(id.Value);
                        post.UpdatePostStatus(Domain.Enum.PostStatusEnum.Published, User.Identity.Name);
                        await _postsApprovalFlowService.UpdatePost(post);

                        return RedirectToAction("Index");
                    }
                    break;
                case "REJECT":
                    if (id.HasValue)
                    {
                        var post = await _postsService.GetPost(id.Value);
                        post.UpdatePostStatus(Domain.Enum.PostStatusEnum.Draft, User.Identity.Name);
                        await _postsApprovalFlowService.UpdatePost(post);

                        return RedirectToAction("Index");
                    }
                    break;
                case "DELETE":
                    if (id.HasValue)
                    {
                        await _postsApprovalFlowService.RemovePost(id.Value);
                        return RedirectToAction("Index");
                    }
                    break;
            }

            if (id.HasValue)
            {
                var post = await _postsService.GetPost(id.Value);
                if (post != null)
                {
                    model.Title = post.Title;
                    model.Text = post.Text;
                    model.PostStatusId = post.PostStatusId;
                    model.PostStatusName = post.PostStatus.Name;
                }
            }
            else
                model.PostStatusName = "Draft";

            return View(model);
        }