public async Task <IActionResult> PostComment(RequestCommentDto requestComment) { var userId = GetUserId(); requestComment.UserId = userId; var post = await _postService.GetOne((int)requestComment.PostId); var comment = await _commentService.AddOne(requestComment); if (requestComment.ParentId != null) { var parentComment = await _commentService.GetOne((int)requestComment.ParentId); await _notificationService.CreateOne(parentComment.UserId, userId, (int)requestComment.PostId, NotificationType.CommentReply); } else { await _notificationService.CreateOne(post.UserId, userId, (int)requestComment.PostId, NotificationType.PostComment); } await _unitOfWork.Commit(); var responseComment = await _commentService.MapModelToResponseComment(comment, userId); return(Ok(responseComment)); }
public async Task <Comment> AddOne(RequestCommentDto requestComment) { var comment = _mapper.Map <Comment>(requestComment); comment.CreatedDate = DateTime.UtcNow; await _commentRepo.Add(comment); return(comment); }