public async Task <IActionResult> DeleteNotification(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePushNotification))
            {
                return(AccessDeniedView());
            }

            var pushNotification = await _pushNotificationService.GetPushNotificationByIdAsync(id);

            if (pushNotification == null)
            {
                return(RedirectToAction("Index"));
            }

            try
            {
                IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
                // Validate that the job doesn't already exists
                if (pushNotification.RemindMe)
                {
                    if (pushNotification.PushNotificationDevices != null)
                    {
                        foreach (var item in pushNotification.PushNotificationDevices)
                        {
                            if (await scheduler.CheckExists(new JobKey(item.JobName, item.JobGroup)))
                            {
                                await scheduler.DeleteJob(new JobKey(item.JobName, item.JobGroup));
                            }
                        }
                    }
                }

                _pushNotificationService.DeletePushNotification(pushNotification);

                _notificationService.SuccessNotification("Push Notification has been deleted successfully.");

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                _notificationService.ErrorNotification(e.Message);
                return(RedirectToAction("EditNotification", new { id = pushNotification.Id }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeletePushNotification(int id)
        {
            if (id <= 0)
            {
                return(await Error(HttpStatusCode.BadRequest, "id", "Invalid id"));
            }

            var pushNotification = _pushNotificationApiService.GetPushNotificationById(id);

            if (pushNotification == null)
            {
                return(await Error(HttpStatusCode.NotFound, "push_notification", "not found"));
            }

            _pushNotificationService.DeletePushNotification(pushNotification);

            await UserActivityService.InsertActivityAsync("DeletePushNotification", $"Deleted a push notification (ID = {id})", pushNotification);

            return(new RawJsonActionResult("{}"));
        }