Beispiel #1
0
        public async Task <IActionResult> OnGet()
        {
            Post = await _blogService.GetPostAsync(PostUrl.GetDate(), PostUrl.Slug);

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

            Comments = await _blogService.GetCommentsAsync(Post.FileName);
            await BuildSeeAlsoAsync(Post);

            return(Page());
        }
Beispiel #2
0
        public async Task <IActionResult> OnPost()
        {
            // Can't use authorization filters on single methods
            if (User.Identity?.IsAuthenticated != true)
            {
                return(Challenge());
            }

            Post = await _blogService.GetPostAsync(PostUrl.GetDate(), PostUrl.Slug);

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

            if (ModelState.IsValid)
            {
                var form = CommentForm;
                Debug.Assert(form != null, "Model can not be valid with null form");
                var id = await _blogService.CreateCommentAsync(
                    Post.FileName,
                    form.ParentId,
                    AuthorName,
                    AuthorEmail,
                    form.Markdown);

                if (id != null)
                {
                    CommentForm = null;

                    return(RedirectToPage(nameof(Post), null, null, $"c{id}"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Unable to save comment.");
                }
            }

            // If we got to here, the input is wrong.
            Comments = await _blogService.GetCommentsAsync(Post.FileName);
            await BuildSeeAlsoAsync(Post);

            return(Page());
        }