private void CreateAlert(DefinedValueCache audience)
        {
            if (audience == null)
            {
                maPopup.Show("The audience is not defined.", ModalAlertType.Information);
                return;
            }

            RockContext rockContext = new RockContext();

            AlertNotificationService alertNotificationService = new AlertNotificationService(rockContext);
            AlertMessageService      alertMessageService      = new AlertMessageService(rockContext);

            int alertTypeId = 31480;

            var alertnotification = new AlertNotification
            {
                Title = lAlertTitle.Text,
                AlertNotificationTypeValueId = alertTypeId,
                AudienceValueId = audience.Id,
                IsActive        = true,
            };

            alertNotificationService.Add(alertnotification);

            rockContext.SaveChanges();

            var alertMessage = new AlertMessage
            {
                AlertNotificationId = alertnotification.Id,
                Message             = lMessage.Text,
            };

            alertMessageService.Add(alertMessage);


            rockContext.SaveChanges();



            alertMessage.SendCommunication(GetAttributeValue("From").AsGuid());

            mdCustomMessage.Hide();
            mdLockdownAlert.Hide();

            maPopup.Show("The LockDown message has been sent.", ModalAlertType.Information);
        }
Ejemplo n.º 2
0
        protected void btnStaff_Click(object sender, EventArgs e)
        {
            GetStaff();

            RockContext rockContext = new RockContext();

            AlertNotificationService alertNotificationService = new AlertNotificationService(rockContext);
            AlertMessageService      alertMessageService      = new AlertMessageService(rockContext);

            int alertTypeId     = 31480;
            int alertAudienceId = 31476;

            var alertnotification = new AlertNotification
            {
                Title = lAlertTitle.Text,
                AlertNotificationTypeValueId = alertTypeId,
                AudienceValueId = alertAudienceId,
                IsActive        = true,
            };



            alertNotificationService.Add(alertnotification);

            rockContext.SaveChanges();



            alertMessageService.Add(new AlertMessage
            {
                AlertNotificationId = alertnotification.Id,
                Message             = lMessage.Text,
                CommunicationId     = 40558,
            });

            rockContext.SaveChanges();
        }