示例#1
0
        public IActionResult ChangePostState(int postId, string action, string approver)
        {
            var post = _postsLogic.GetPost(postId);

            if (post.WorkflowStates == States.PendingApproval && actions.Contains(action))
            {
                post.WorkflowStates = action.Equals("approve") ? States.Publish : States.Draft;
                post.Approver       = approver;
                post.ApprovalDate   = DateTime.Now;
                _postsLogic.AddOrEdit(post);
                return(Ok(post));
            }
            return(BadRequest());
        }
        public IActionResult Add(PostViewModel postView)
        {
            var post = GetPost(postView);

            post.WorkflowStates = Request.Form.Keys.Contains("Save") ? States.Draft : Request.Form.Keys.Contains("submitApproval") ? States.PendingApproval : States.Publish;
            if (post.WorkflowStates == States.Publish && String.IsNullOrEmpty(Request.Form["Approver"]))
            {
                ModelState.AddModelError("Approver", "The approver is required");
                return(View("~/Views/Post/Add.cshtml", postView));
            }

            if (ModelState.IsValid)
            {
                if (post.WorkflowStates == States.Publish)
                {
                    post.ApprovalDate = DateTime.Now;
                }

                _postsLogic.AddOrEdit(post);
                return(RedirectToAction("Manage"));
            }
            return(View(postView));
        }