Beispiel #1
0
 public IActionResult CommentPost([FromBody] CommentPostInDto input)
 {
     if (ModelState.IsValid)
     {
         var result = _postService.Commenting(input.BlogId, input);
         if (result.OKStatus)
         {
             return(Ok());
         }
         else
         {
             return(Redirect("/Account/Login?ReturnUrl=/"));
         }
     }
     return(BadRequest());
 }
Beispiel #2
0
        public ServiceResponse Commenting(int blogId, CommentPostInDto input)
        {
            var post = _postRepository.Get()
                       .Where(x => x.Id == input.BlogId)
                       .Include(x => x.Comments)
                       .FirstOrDefault();
            var user = GetAuthenticatedUser();

            if (user.IsAuthenticated)
            {
                post.AddComment(input.Content, user.UserId, user.UserName);
                _postRepository.Complete();
                s_diagnosticListener.WriteAddPostCommentAfter(post.Id);
                return(ServiceResponse.OK());
            }
            return(ServiceResponse.Unauthorized());
        }