示例#1
0
        public async Task <HttpResponseMessage> CancelPushNotificationAlert(int userId)
        {
            var userrepo = new UserRepository();
            var user     = userrepo.Get(userId);

            var schedule = user.UserTrackingSchedules.Where(_ => _.Enabled).FirstOrDefault();

            if (schedule != null && schedule.Enabled && schedule.ScheduledNotificationId != string.Empty)
            {
                NotificationHubClient hub = NotificationHubClient
                                            .CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
                await hub.CancelNotificationAsync(schedule.ScheduledNotificationId);
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        /// <summary>
        /// スケジュールされた通知を削除します
        /// </summary>
        public async Task <ScheduleLog> Delete(CancelScheduleFormModel data)
        {
            // 送信されたデータが正しいか検証する
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            // スケジュールキャンセルリクエストを非同期で送信
            await _client.CancelNotificationAsync(data.ScheduledNotificationId);

            // キャンセル日時を DB へ保存
            var entity = _context.ScheduleLogs.First(p => p.NotificationId == data.ScheduledNotificationId);

            entity.CancelledOn = DateTimeOffset.UtcNow;

            await _context.SaveChangesAsync();

            return(entity);
        }