コード例 #1
0
ファイル: CommentController.cs プロジェクト: ropkezas/simoona
        public async Task <IHttpActionResult> CreateComment(NewCommentViewModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var commentDto = _mapper.Map <NewCommentViewModel, NewCommentDTO>(comment);

            SetOrganizationAndUser(commentDto);

            try
            {
                var commentCreatedDto = _commentService.CreateComment(commentDto);

                var membersToNotify = _wallService.GetWallMembersIds(commentCreatedDto.WallId, commentDto);
                NotificationHub.SendWallNotification(commentCreatedDto.WallId, membersToNotify, commentCreatedDto.WallType, GetUserAndOrganizationHub());

                var commentsAuthorsToNotify = _commentService.GetCommentsAuthorsToNotify(
                    commentDto.PostId,
                    new List <string>()
                {
                    commentCreatedDto.CommentCreator
                });

                if (commentCreatedDto.PostCreator != commentCreatedDto.CommentCreator && _commentService.IsPostAuthorAppNotificationsEnabled(commentCreatedDto.PostCreator))
                {
                    var notificationAuthorDto = await _notificationService.CreateForComment(GetUserAndOrganization(), commentCreatedDto, NotificationType.WallComment, new List <string> {
                        commentCreatedDto.PostCreator
                    });

                    if (notificationAuthorDto != null)
                    {
                        NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationAuthorDto), GetUserAndOrganizationHub(), new List <string>()
                        {
                            commentCreatedDto.PostCreator
                        });
                    }

                    commentsAuthorsToNotify.Remove(commentCreatedDto.PostCreator);
                }

                if (commentsAuthorsToNotify.Count > 0)
                {
                    var notificationDto = await _notificationService.CreateForComment(GetUserAndOrganization(), commentCreatedDto, NotificationType.FollowingComment, commentsAuthorsToNotify);

                    if (notificationDto != null)
                    {
                        NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), GetUserAndOrganizationHub(), commentsAuthorsToNotify);
                    }
                }

                return(Ok(new { commentCreatedDto.CommentId }));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }
コード例 #2
0
        public async Task <NotificationDto> CreateForWall(UserAndOrganizationDTO userOrg, CreateWallDto wallDto, int wallId)
        {
            var mainWallId = await _wallDbSet.Where(w => w.Type == WallType.Main).Select(s => s.Id).SingleAsync();

            var membersToNotify = _wallService.GetWallMembersIds(mainWallId, userOrg);
            var newNotification = Notification.Create(wallDto.Name, wallDto.Description, wallDto.Logo, new Sources {
                WallId = wallId
            }, NotificationType.NewWall, userOrg.OrganizationId, membersToNotify);

            _notificationDbSet.Add(newNotification);

            await _uow.SaveChangesAsync();

            return(_mapper.Map <NotificationDto>(newNotification));
        }
コード例 #3
0
        public void Notify(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto)
        {
            _commentEmailNotificationService.SendEmailNotification(commentDto);

            var membersToNotify = _wallService.GetWallMembersIds(commentDto.WallId, userHubDto);

            NotificationHub.SendWallNotification(commentDto.WallId, membersToNotify, commentDto.WallType, userHubDto);

            var postWatchers = _postService.GetPostWatchersForAppNotifications(commentDto.PostId).ToList();

            // Comment author doesn't need to receive notification about his own comment
            postWatchers.Remove(commentDto.CommentCreator);

            // Send notification to other users
            if (postWatchers.Count > 0)
            {
                SendNotification(commentDto, userHubDto, NotificationType.FollowingComment, postWatchers);
            }
        }
コード例 #4
0
        public void Notify(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto)
        {
            _commentNotificationService.NotifyAboutNewComment(commentDto);

            var membersToNotify = _wallService.GetWallMembersIds(commentDto.WallId, userHubDto);

            NotificationHub.SendWallNotification(commentDto.WallId, membersToNotify, commentDto.WallType, userHubDto);

            var commentsAuthorsToNotify = _commentService.GetCommentsAuthorsToNotify(
                commentDto.PostId,
                new List <string>()
            {
                commentDto.CommentCreator
            });

            if (commentDto.PostCreator != commentDto.CommentCreator && _commentService.IsPostAuthorAppNotificationsEnabled(commentDto.PostCreator))
            {
                var notificationAuthorDto = _notificationService.CreateForComment(userHubDto, commentDto, NotificationType.WallComment, new List <string> {
                    commentDto.PostCreator
                }).GetAwaiter().GetResult();
                if (notificationAuthorDto != null)
                {
                    NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationAuthorDto), userHubDto, new List <string>()
                    {
                        commentDto.PostCreator
                    });
                }

                commentsAuthorsToNotify.Remove(commentDto.PostCreator);
            }

            if (commentsAuthorsToNotify.Count > 0)
            {
                var notificationDto = _notificationService.CreateForComment(userHubDto, commentDto, NotificationType.FollowingComment, commentsAuthorsToNotify).GetAwaiter().GetResult();
                if (notificationDto != null)
                {
                    NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), userHubDto, commentsAuthorsToNotify);
                }
            }
        }