コード例 #1
0
        public async Task <ViewCommentDto> AddComment(string userId, int topicId, CommentDto commentDto)
        {
            var topic = await _topicService.GetTopic(topicId);

            var comment = new Comment
            {
                Content = commentDto.Content,
                UserId  = userId,
                TopicId = topicId
            };

            await Do(async() => await _context.Comments.AddAsync(comment));

            comment.User = await _userService.GetUserById(userId);

            if (userId != topic.UserId)
            {
                await _notificationService.NotifyComment(comment.User, topic, comment.Id);
            }

            var dto = ViewCommentDto.Create(userId, comment);

            _topicsHub.SendComment(topic.Id, dto);

            return(dto);
        }
コード例 #2
0
 public static async void SendComment(this IHubContext <TopicsHub> hub, int topicId, ViewCommentDto comment)
 {
     await hub.Clients.Group(topicId.ToString()).SendAsync("ReceiveComment", comment);
 }