Exemplo n.º 1
0
        public async Task ChangeUserNotificationSettings(UserNotificationsSettingsDto settingsDto, UserAndOrganizationDTO userOrg)
        {
            var settings = await _usersDbSet
                           .Where(u => u.Id == userOrg.UserId && u.OrganizationId == userOrg.OrganizationId)
                           .Select(u => u.NotificationsSettings)
                           .FirstOrDefaultAsync();

            if (settings == null)
            {
                settings = new NotificationsSettings
                {
                    OrganizationId = userOrg.OrganizationId
                };
                var user = await _usersDbSet.FirstAsync(u => u.Id == userOrg.UserId && u.OrganizationId == userOrg.OrganizationId);

                user.NotificationsSettings = settings;
            }

            settings.ModifiedBy                       = userOrg.UserId;
            settings.EventsAppNotifications           = settingsDto.EventsAppNotifications;
            settings.EventsEmailNotifications         = settingsDto.EventsEmailNotifications;
            settings.ProjectsAppNotifications         = settingsDto.ProjectsAppNotifications;
            settings.ProjectsEmailNotifications       = settingsDto.ProjectsEmailNotifications;
            settings.MyPostsAppNotifications          = settingsDto.MyPostsAppNotifications;
            settings.MyPostsEmailNotifications        = settingsDto.MyPostsEmailNotifications;
            settings.FollowingPostsAppNotifications   = settingsDto.FollowingPostsAppNotifications;
            settings.FollowingPostsEmailNotifications = settingsDto.FollowingPostsEmailNotifications;

            await _uow.SaveChangesAsync(userOrg.UserId);
        }
Exemplo n.º 2
0
        public async Task <UserNotificationsSettingsDto> GetWallNotificationSettings(UserAndOrganizationDTO userOrg)
        {
            var settings = await _usersDbSet
                           .Where(u => u.Id == userOrg.UserId && u.OrganizationId == userOrg.OrganizationId)
                           .Select(u => u.NotificationsSettings)
                           .FirstOrDefaultAsync();

            var settingsDto = new UserNotificationsSettingsDto
            {
                EventsAppNotifications           = settings?.EventsAppNotifications ?? true,
                EventsEmailNotifications         = settings?.EventsEmailNotifications ?? true,
                ProjectsAppNotifications         = settings?.ProjectsAppNotifications ?? true,
                ProjectsEmailNotifications       = settings?.ProjectsEmailNotifications ?? true,
                MyPostsAppNotifications          = settings?.MyPostsAppNotifications ?? true,
                MyPostsEmailNotifications        = settings?.MyPostsEmailNotifications ?? true,
                FollowingPostsAppNotifications   = settings?.FollowingPostsAppNotifications ?? true,
                FollowingPostsEmailNotifications = settings?.FollowingPostsEmailNotifications ?? true,

                Walls = _wallMembersDbSet
                        .Include(x => x.Wall)
                        .Where(x => x.UserId == userOrg.UserId && x.Wall != null && x.Wall.OrganizationId == userOrg.OrganizationId)
                        .Where(x => x.Wall.Type == WallType.UserCreated || x.Wall.Type == WallType.Main)
                        .Select(x => new WallNotificationsDto()
                {
                    WallName   = x.Wall.Name,
                    WallId     = x.WallId,
                    IsMainWall = x.Wall.Type == WallType.Main,
                    IsAppNotificationEnabled   = x.AppNotificationsEnabled,
                    IsEmailNotificationEnabled = x.EmailNotificationsEnabled
                })
            };

            return(settingsDto);
        }
Exemplo n.º 3
0
        public void Should_Change_User_Wall_Notification_Settings()
        {
            // Arrange
            MockUserWallNotifications();

            var userAndOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 1,
                UserId         = "UserId"
            };

            var notificationSettings = new List <WallNotificationsDto>()
            {
                new WallNotificationsDto()
                {
                    WallId = 1,
                    IsAppNotificationEnabled   = false,
                    IsEmailNotificationEnabled = false
                },
                new WallNotificationsDto()
                {
                    WallId = 3,
                    IsAppNotificationEnabled   = true,
                    IsEmailNotificationEnabled = true,
                },
                new WallNotificationsDto()
                {
                    WallId = 4,
                    IsAppNotificationEnabled   = false,
                    IsEmailNotificationEnabled = false
                },
            };

            UserNotificationsSettingsDto userSettings = new UserNotificationsSettingsDto
            {
                Walls = notificationSettings,
                EventsAppNotifications     = true,
                EventsEmailNotifications   = true,
                ProjectsAppNotifications   = true,
                ProjectsEmailNotifications = true
            };

            // Act
            _userService.ChangeWallNotificationSettings(userSettings, userAndOrg);

            // Assert
            Assert.AreEqual(
                true,
                _wallUsersDbSet.First(x => x.WallId == 1).EmailNotificationsEnabled);

            Assert.AreEqual(
                true,
                _wallUsersDbSet.First(x => x.WallId == 3).EmailNotificationsEnabled);

            Assert.AreEqual(
                true,
                _wallUsersDbSet.First(x => x.WallId == 4).EmailNotificationsEnabled);
        }
Exemplo n.º 4
0
        public void ChangeWallNotificationSettings(UserNotificationsSettingsDto userNotificationsSettingsDto, UserAndOrganizationDTO userOrg)
        {
            var wallIdsToUpdate = userNotificationsSettingsDto
                                  .Walls
                                  .Select(x => x.WallId)
                                  .ToList();

            var wallMembers = _wallMembersDbSet
                              .Include(x => x.Wall)
                              .Where(x => x.UserId == userOrg.UserId &&
                                     x.Wall.OrganizationId == userOrg.OrganizationId &&
                                     wallIdsToUpdate.Contains(x.WallId) &&
                                     x.Wall.Type == WallType.UserCreated)
                              .ToList();

            foreach (var member in wallMembers)
            {
                member.EmailNotificationsEnabled = userNotificationsSettingsDto
                                                   .Walls
                                                   .First(x => x.WallId == member.WallId)
                                                   .IsEmailNotificationEnabled;

                member.AppNotificationsEnabled = userNotificationsSettingsDto
                                                 .Walls
                                                 .First(x => x.WallId == member.WallId)
                                                 .IsAppNotificationEnabled;
            }

            var eventOrProjectMembers = _wallMembersDbSet
                                        .Include(x => x.Wall)
                                        .Where(x => x.UserId == userOrg.UserId &&
                                               x.Wall.OrganizationId == userOrg.OrganizationId &&
                                               (x.Wall.Type == WallType.Events ||
                                                x.Wall.Type == WallType.Project))
                                        .ToList();

            foreach (var member in eventOrProjectMembers)
            {
                switch (member.Wall.Type)
                {
                case WallType.Events:
                    member.EmailNotificationsEnabled = userNotificationsSettingsDto.EventsEmailNotifications;
                    member.AppNotificationsEnabled   = userNotificationsSettingsDto.EventsAppNotifications;
                    break;

                case WallType.Project:
                    member.EmailNotificationsEnabled = userNotificationsSettingsDto.EventsEmailNotifications;
                    member.AppNotificationsEnabled   = userNotificationsSettingsDto.EventsAppNotifications;
                    break;
                }
            }

            _uow.SaveChanges(userOrg.UserId);
        }