Beispiel #1
0
        public IActionResult AddComment([FromBody] Comment comment, [FromQuery] string lang)
        {
            if (string.IsNullOrWhiteSpace(comment.Content))
            {
                return(Ok());
            }

            if (!postsManager.AddComment(comment.PostId, User.Identity.Name, comment.Content))
            {
                var error = localizer["CommentNoAdded"];
                return(StatusCode(StatusCodes.Status500InternalServerError, error));
            }

            return(Ok());
        }
 public IActionResult AddComment(int PostId, string Comment)
 {
     try
     {
         var user   = _userManager.GetUserAsync(User).Result;
         var result = _postManager.AddComment(new Models.Comment()
         {
             CommentDate = DateTime.Now, Content = Comment, PostId = PostId, UserId = user.Id, User = $"{user.Name} {user.Surname}"
         });
         return(Ok(new CommentDto {
             CommentDate = result.Entity.CommentDate, Content = result.Entity.Content, User = result.Entity.User, PostId = result.Entity.PostId, Id = result.Entity.Id
         }));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Beispiel #3
0
        private void addComment(UserDTO user, List <PostDTO> post, int id)
        {
            Console.WriteLine("Enter your comment");
            string     comment = Console.ReadLine();
            CommentDTO com     = new CommentDTO();

            com.AuthorID   = user.UserId;
            com.InsertTime = DateTime.UtcNow;
            com.Likes      = 0;
            com.UpdateTime = DateTime.UtcNow;
            com.Text       = comment;
            foreach (PostDTO p in post)
            {
                if (id == p.PostId)
                {
                    _postManager.AddComment(id, com);
                }
            }
        }