Beispiel #1
0
        public async Task <IActionResult> Create(
            [FromBody] CommentCreationContext.CommentForm commentForm,
            [FromServices] CommentCreationContext commentCreationContext)
        {
            try
            {
                var comment = await commentCreationContext
                              .Setup(UserId)
                              .CreateAsync(commentForm);

                return(Ok(CommentViewModels.Create(comment)));
            }
            catch (CommentCreationContext.ParentNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> CreateComment(
            [FromBody] CommentCreationContext.CommentForm commentForm,
            [FromServices] CommentCreationContext commentCreationContext)
        {
            try
            {
                // Provide UserId when creating comment, so we know who it belongs to
                var comment = await commentCreationContext
                              .Setup(UserId)
                              .CreateCommentAsync(commentForm);

                // Return ok with created comment
                return(Ok(CommentViewModels.Create(comment)));
            }
            catch (CommentCreationContext.ParentNotFoundException e)
            {
                return(BadRequest(e.Message));
            }
        }