Example #1
0
        public async Task <IActionResult> PostEdit([FromRoute] string slug, [FromForm] PostEditViewModel postViewModel)
        {
            if (!string.IsNullOrEmpty(slug))
            {
                var existingPost = await _postService.GetPost(slug);

                if (existingPost == null)
                {
                    return(NotFound());
                }
            }

            var post = postViewModel.AsModel();

            post.Status = Services.PostStatus.Draft;

            var result = await _postService.SavePost(post);

            if (!result.Success)
            {
                // TODO: Show result.Error;
            }

            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
        public async Task <IActionResult> PostApprove([FromRoute] string slug)
        {
            var post = await _postService.GetPost(slug);

            if (post == null)
            {
                return(NotFound());
            }

            post.Status       = Services.PostStatus.Published;
            post.ApprovalDate = DateTime.Now;

            var result = await _postService.SavePost(post);

            if (!result.Success)
            {
                // TODO: Show result.Error;
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Approve([FromRoute] string slug)
        {
            var post = await _postService.GetPost(slug);

            if (post?.Status != Services.PostStatus.Pending)
            {
                return(NotFound());
            }

            post.Status       = Services.PostStatus.Published;
            post.ApprovalDate = DateTime.Now;

            var result = await _postService.SavePost(post);

            if (!result.Success)
            {
                return(this.UnprocessableEntity(result.Error));
            }

            return(Ok());
        }