public async Task <IActionResult> Create( [FromBody] CommentForm commentForm, [FromServices] CommentCreationContext commentCreationContext) { try { var comment = await commentCreationContext .Setup(UserId) .CreateAsync(commentForm); return(Ok(CommentViewModel.Create(comment))); } catch (CommentCreationContext.ParentNotFoundException e) { return(BadRequest(e.Message)); } }
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)); } }