Beispiel #1
0
        /// <summary>
        /// The RefreshPushNotificationToken.
        /// </summary>
        /// <param name="token">The token<see cref="PushNotificationToken"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task RefreshPushNotificationToken(PushNotificationToken token)
        {
            try
            {
                if (token.Role == Role.Student.ToString())
                {
                    var students = await _tableStorage.GetAllAsync <Student>("Student");

                    var student = students.SingleOrDefault(s => s.RowKey == token.Id);

                    student.NotificationToken = token.RefreshToken;
                    student.UpdatedOn         = DateTime.UtcNow;
                    student.UpdatedBy         = token.Id;

                    await _tableStorage.UpdateAsync("Student", student);
                }
                else
                {
                    var users = await _tableStorage.GetAllAsync <User>("User");

                    var user = users.SingleOrDefault(u => u.RowKey == token.Id);

                    user.NotificationToken = token.RefreshToken;
                    user.UpdatedOn         = DateTime.UtcNow;
                    user.UpdatedBy         = token.Id;

                    await _tableStorage.UpdateAsync("User", user);
                }
            }
            catch (Exception ex)
            {
                throw new AppException("Error: Refresh push notification token ", ex.InnerException);
            }
        }
Beispiel #2
0
        public async Task RemovePushNotificationToken(PushNotificationToken token)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.PushNotificationTokens
                .RemoveRange(DataContext.PushNotificationTokens
                             .Where(t => t.Token == token.Token));

                await DataContext.SaveChangesAsync();
            }
        }
Beispiel #3
0
        public async Task SavePushNotificationToken(PushNotificationToken token)
        {
            using (DataContext = new UptimeHippoDataContext())
            {
                DataContext.PushNotificationTokens
                .RemoveRange(DataContext.PushNotificationTokens
                             .Where(t => t.Token == token.Token));

                DataContext.PushNotificationTokens.Add(token);

                await DataContext.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task <IActionResult> UnRegisterPushNotifications([FromBody] PushNotificationModel model)
        {
            try
            {
                var pushNotificationToken = new PushNotificationToken
                {
                    Token = model.Token
                };

                await _pushNotificationTokensRepository.RemovePushNotificationToken(pushNotificationToken);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                return(BadRequest(new ErrorMessage(ex)));
            }
        }
Beispiel #5
0
        public async Task <IActionResult> RegisterPushNotifications([FromBody] PushNotificationModel model)
        {
            try
            {
                var user = await GetCurrentAuthenticatedUser();

                var pushNotificationToken = new PushNotificationToken
                {
                    Token             = model.Token,
                    ApplicationUserId = user.Id
                };

                await _pushNotificationTokensRepository.SavePushNotificationToken(pushNotificationToken);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                return(BadRequest(new ErrorMessage(ex)));
            }
        }