Example #1
0
        public async Task <ActionResult <CommentDtoOut> > CreateComment(int id, AddCommentDtoIn comment)
        {
            (await new AddCommentDtoInValidator().ValidateAsync(comment)).AddToModelState(ModelState, null);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId     = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var newComment = await _postRepository.AddCommentAsync(userId, id, comment.Content);

            return(CreatedAtAction(nameof(GetComment), new { id = newComment.Id }, newComment));
        }
Example #2
0
        public async Task <IActionResult> AddNewComment([FromForm] CommentForCreationDto newComment)
        {
            var identity = HttpContext.User.Identity as ClaimsIdentity;
            IEnumerable <Claim> claim = identity.Claims;
            var usernameClaim         = claim
                                        .Where(x => x.Type == ClaimTypes.Name)
                                        .FirstOrDefault();
            CommentForDisplayDto ret;

            if (usernameClaim != null)
            {
                ret = await _rep.AddCommentAsync(newComment.IdPosta, usernameClaim.Value, newComment.CommentText);
            }
            else
            {
                return(BadRequest());
            }
            return(Ok(ret));
        }