Beispiel #1
0
        public async Task <NotificationSettingsDto> GetUserNotificationsSettings(int userId)
        {
            var notificationSettings = new NotificationSettingsDto();

            using (var sqlConnection = await _databaseConnectionFactory.CreateConnectionAsync())
            {
                try
                {
                    notificationSettings.UserNotifications = (await sqlConnection.QueryAsync <UserNotificationSettingsDto>(SQLQueryConstants.GetUsersNotificationSettingsQuery, new { UserId = userId })).ToList();
                    if (notificationSettings.UserNotifications.Where(x => x.UserNotificationSet == true).Count() == (await AllAsync()).Count())
                    {
                        notificationSettings.AllAboveNotifications = true;
                    }
                    else
                    {
                        notificationSettings.AllAboveNotifications = false;
                    }
                    return(notificationSettings);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }
        }
Beispiel #2
0
        private async Task UpsertUserAsync(IUser user)
        {
            if (client == null)
            {
                return;
            }

            var settings = new NotificationSettingsDto
            {
                [Providers.WebPush] = new NotificationSettingDto
                {
                    Send           = NotificationSend.Send,
                    DelayInSeconds = null
                },

                [Providers.Email] = new NotificationSettingDto
                {
                    Send           = NotificationSend.Send,
                    DelayInSeconds = 5 * 60
                }
            };

            var userRequest = new UpsertUserDto
            {
                Id                = user.Id,
                FullName          = user.Claims.DisplayName(),
                PreferredLanguage = "en",
                PreferredTimezone = null,
                Settings          = settings,
            };

            if (user.Email.IsEmail())
            {
                userRequest.EmailAddress = user.Email;
            }

            var response = await client.Users.PostUsersAsync(options.AppId, new UpsertUsersDto
            {
                Requests = new List <UpsertUserDto>
                {
                    userRequest
                }
            });

            await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey);
        }
        private static NotificationSettingsModel ToModel(this NotificationSettingsDto setting)
        {
            if (setting == null)
            {
                return(null);
            }

            return(new NotificationSettingsModel
            {
                MainServerPort = setting.MainServerPort,
                IsSslEnabled = setting.IsSslEnabled,
                MailBox = setting.MailBox,
                MailServerHost = setting.MailServerHost,
                Password = setting.Password,
                UserName = setting.UserName
            });
        }
        public async Task <bool> Update(int employeeId, NotificationSettingsDto notificationSettingsDto)
        {
            if (notificationSettingsDto == null)
            {
                throw new ArgumentNullException(nameof(notificationSettingsDto));
            }

            var notificationSettings = await _notificationSettingsRepository.GetByEmployeeId(employeeId);

            if (notificationSettings == null)
            {
                throw new InvalidOperationException();
            }

            _mapper.Map(notificationSettingsDto, notificationSettings);
            await _notificationSettingsRepository.Update(notificationSettings);

            return(await _notificationSettingsRepository.Update(notificationSettings));
        }
Beispiel #5
0
        private async Task UpsertUserAsync(IUser user)
        {
            if (client == null)
            {
                return;
            }

            var settings = new NotificationSettingsDto();

            settings.Channels[Providers.WebPush] = new NotificationSettingDto
            {
                Send           = true,
                DelayInSeconds = null
            };

            settings.Channels[Providers.Email] = new NotificationSettingDto
            {
                Send           = true,
                DelayInSeconds = 5 * 60
            };

            var userRequest = new UpsertUserRequest
            {
                AppId                    = options.AppId,
                FullName                 = user.DisplayName(),
                PreferredLanguage        = "en",
                PreferredTimezone        = null,
                RequiresWhitelistedTopic = true,
                Settings                 = settings,
                UserId                   = user.Id
            };

            if (user.Email.IsEmail())
            {
                userRequest.EmailAddress = user.Email;
            }

            var response = await client.UpsertUserAsync(userRequest);

            await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.User.ApiKey);
        }
        public async Task <IActionResult> Put(int employeeId, NotificationSettingsDto notificationSettingsDto)
        {
            var isUpdated = await _notificationSettingsService.Update(employeeId, notificationSettingsDto);

            return(Ok(isUpdated));
        }