Пример #1
0
        public async Task <CreateCommentResponse> Handle(CreateCommentRequest request,
                                                         CancellationToken cancellationToken)
        {
            var createdComment = await commentService.CreateComment(request.Content, request.PostId) ??
                                 throw new CrudException("Comment has not been created");

            if (httpContextReader.CurrentUserId != createdComment.UserId)
            {
                await notifier.Push(
                    NotificationMessages.NewCommentNotification(createdComment.User.Username,
                                                                createdComment.Post.Title), createdComment.Post.AuthorId, NotificationType.NewComment);
            }

            return(new CreateCommentResponse {
                Comment = mapper.Map <CommentDto>(createdComment)
            });
        }