/// <summary>
        /// Handles the Click event of the btnSaveActionSettings control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSaveActionSettings_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            var action      = new SmsActionService(rockContext).Get(hfEditActionId.Value.AsInteger());

            action.Name     = tbName.Text;
            action.IsActive = cbActive.Checked;
            action.ContinueAfterProcessing = cbContinue.Checked;
            action.ExpireDate = dpExpireDate.SelectedDate;

            avcFilters.GetEditValues(action);
            avcAttributes.GetEditValues(action);

            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();

                action.SaveAttributeValues();
            });

            SmsActionCache.Clear();

            pnlEditAction.Visible = false;
            hfEditActionId.Value  = string.Empty;
            BindActions();
        }
예제 #2
0
        /// <summary>
        /// Binds the actions repeater.
        /// </summary>
        private void BindActions()
        {
            var rockContext      = new RockContext();
            var smsActionService = new SmsActionService(rockContext);

            var actions = smsActionService.Queryable()
                          .OrderBy(a => a.Order)
                          .ThenBy(a => a.Id)
                          .ToList()
                          .Select(a => new
            {
                a.Id,
                a.Name,
                a.SmsActionComponentEntityTypeId,
                a.IsActive,
                a.ContinueAfterProcessing,
                Component = SmsActionContainer.GetComponent(EntityTypeCache.Get(a.SmsActionComponentEntityTypeId).Name)
            })
                          .ToList();

            if (actions.Any())
            {
                olActions.RemoveCssClass("drag-container-empty");
            }
            else
            {
                olActions.AddCssClass("drag-container-empty");
            }

            rptrActions.DataSource = actions;
            rptrActions.DataBind();
        }
예제 #3
0
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments = argument.SplitDelimitedValues();

            //
            // Check for the event to add a new action.
            //
            if (segments.Length == 3 && segments[0] == "add-action")
            {
                var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                var order           = segments[2].AsInteger();

                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var action = new SmsAction
                {
                    SmsPipelineId = GetSmsPipelineId().Value,
                    Name          = actionComponent.Title,
                    IsActive      = true,
                    Order         = order,
                    SmsActionComponentEntityTypeId = actionComponent.TypeId
                };

                smsActionService.Queryable()
                .Where(a => a.Order >= order)
                .ToList()
                .ForEach(a => a.Order += 1);

                smsActionService.Add(action);

                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }

            //
            // Check for the event to drag-reorder actions.
            //
            else if (segments.Length == 3 && segments[0] == "reorder-action")
            {
                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService.Queryable()
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }
        }
        /// <summary>
        /// Handles the Click event of the btnDeleteAction control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDeleteAction_Click(object sender, EventArgs e)
        {
            var rockContext      = new RockContext();
            var smsActionService = new SmsActionService(rockContext);
            var action           = smsActionService.Get(hfEditActionId.Value.AsInteger());

            smsActionService.Delete(action);
            rockContext.SaveChanges();

            pnlEditAction.Visible = false;

            hfEditActionId.Value = string.Empty;
            BindActions();
        }
예제 #5
0
        /// <summary>
        /// Handles the ItemCommand event of the rptrActions control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rptrActions_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var smsActionService = new SmsActionService(new RockContext());
            var action           = smsActionService.Get(e.CommandArgument.ToString().AsInteger());

            if (e.CommandName == "EditAction")
            {
                var component = SmsActionContainer.GetComponent(EntityTypeCache.Get(action.SmsActionComponentEntityTypeId).Name);

                hfEditActionId.Value = action.Id.ToString();
                lActionType.Text     = component.Title;
                tbName.Text          = action.Name;
                cbActive.Checked     = action.IsActive;
                cbContinue.Checked   = action.ContinueAfterProcessing;

                avcFilters.AddEditControls(action);
                avcAttributes.AddEditControls(action);

                pnlEditAction.Visible = true;

                BindActions();
            }
        }
        /// <summary>
        /// Handles the Click event of the lbSendMessage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSendMessage_Click(object sender, EventArgs e)
        {
            var smsPipelineId = GetSmsPipelineId();

            if (!string.IsNullOrWhiteSpace(tbSendMessage.Text) && smsPipelineId != null)
            {
                var message = new SmsMessage
                {
                    FromNumber = tbFromNumber.Text,
                    ToNumber   = tbToNumber.Text,
                    Message    = tbSendMessage.Text
                };

                if (message.FromNumber.StartsWith("+"))
                {
                    message.FromPerson = new PersonService(new RockContext()).GetPersonFromMobilePhoneNumber(message.FromNumber.Substring(1), true);
                }
                else
                {
                    message.FromPerson = new PersonService(new RockContext()).GetPersonFromMobilePhoneNumber(message.FromNumber, true);
                }

                var outcomes = SmsActionService.ProcessIncomingMessage(message, smsPipelineId.Value);
                var response = SmsActionService.GetResponseFromOutcomes(outcomes);

                var stringBuilder = new StringBuilder();

                if (outcomes != null)
                {
                    foreach (var outcome in outcomes)
                    {
                        if (outcome != null)
                        {
                            stringBuilder.AppendLine(outcome.ActionName);
                            stringBuilder.AppendLine(string.Format("\tShould Process = {0}", outcome.ShouldProcess));

                            if (outcome.Response != null && !outcome.Response.Message.IsNullOrWhiteSpace())
                            {
                                stringBuilder.AppendLine(string.Format("\tResponse = {0}", outcome.Response.Message));
                            }

                            if (!outcome.ErrorMessage.IsNullOrWhiteSpace())
                            {
                                stringBuilder.AppendLine(string.Format("\tError = {0}", outcome.ErrorMessage));
                            }

                            if (outcome.Exception != null)
                            {
                                stringBuilder.AppendLine(string.Format("\tException = {0}", outcome.Exception.Message));
                            }

                            stringBuilder.AppendLine();
                        }
                    }
                }

                preOutcomes.InnerText = stringBuilder.ToString();

                if (response != null)
                {
                    lResponse.Text = response.Message;
                }
                else
                {
                    lResponse.Text = "--No Response--";
                }
            }
            else
            {
                lResponse.Text        = "--Empty Message or No SMS Pipeline Id--";
                preOutcomes.InnerText = string.Empty;
            }
        }
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument      = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments      = argument.SplitDelimitedValues();
            var    smsPipelineId = GetSmsPipelineId();

            if (smsPipelineId == null || segments.Length != 3)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService
                              .Queryable()
                              .Where(a => a.SmsPipelineId == smsPipelineId)
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                // Reset order actions to eliminate gaps.
                for (var i = 0; i < actions.Count; i++)
                {
                    actions[i].Order = i;
                }

                // Check for the event to add a new action.
                if (segments[0] == "add-action")
                {
                    var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                    var order           = segments[2].AsInteger();

                    var action = new SmsAction
                    {
                        SmsPipelineId = smsPipelineId.Value,
                        Name          = actionComponent.Title,
                        IsActive      = true,
                        Order         = order,
                        SmsActionComponentEntityTypeId = actionComponent.TypeId
                    };

                    actions
                    .Where(a => a.Order >= order)
                    .ToList()
                    .ForEach(a => a.Order += 1);

                    smsActionService.Add(action);
                }
                else if (segments[0] == "reorder-action")
                {
                    // Check for the event to drag-reorder actions.
                    smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                }

                rockContext.SaveChanges();
                BindActions();
                SmsActionCache.Clear();
            }
        }