Пример #1
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls(Type entityType, FilterField filterControl)
        {
            RockDropDownList ddlSignalType = new RockDropDownList();

            ddlSignalType.ID       = filterControl.ID + "_ddlSignalType";
            ddlSignalType.CssClass = "js-signal-type-list";
            ddlSignalType.Label    = "Signal Type";
            filterControl.Controls.Add(ddlSignalType);

            var signalTypeService  = new SignalTypeService(new RockContext());
            var entityTypeIdPerson = EntityTypeCache.GetId <Rock.Model.Person>();
            var signalTypes        = signalTypeService.Queryable()
                                     .OrderBy(a => a.Order)
                                     .ThenBy(a => a.Name)
                                     .Select(a => new
            {
                a.Id,
                a.Name
            }).ToList();

            ddlSignalType.Items.Clear();
            ddlSignalType.Items.Add(new ListItem());
            ddlSignalType.Items.AddRange(signalTypes.Select(a => new ListItem(a.Name, a.Id.ToString())).ToArray());

            return(new System.Web.UI.Control[] { ddlSignalType });
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            SignalType signalType        = null;
            var        rockContext       = new RockContext();
            var        signalTypeService = new SignalTypeService(rockContext);

            if (SignalTypeId != 0)
            {
                signalType = signalTypeService.Get(SignalTypeId);
            }

            if (signalType == null)
            {
                signalType = new SignalType();
                signalTypeService.Add(signalType);
            }

            signalType.Name               = tbName.Text;
            signalType.Description        = tbDescription.Text;
            signalType.SignalColor        = cpColor.Text;
            signalType.SignalIconCssClass = tbIconCssClass.Text;

            if (!Page.IsValid || !signalType.IsValid)
            {
                return;
            }

            rockContext.SaveChanges();

            var people = new PersonSignalService(rockContext).Queryable()
                         .Where(s => s.SignalTypeId == signalType.Id)
                         .Select(s => s.PersonId)
                         .Distinct()
                         .ToList();

            //
            // If less than 250 people with this signal type then just update them all now,
            // otherwise put something in the rock queue to take care of it.
            //
            if (people.Count < 250)
            {
                new PersonService(rockContext).Queryable()
                .Where(p => people.Contains(p.Id))
                .ToList()
                .ForEach(p => p.CalculateSignals());

                rockContext.SaveChanges();
            }
            else
            {
                var updatePersonSignalTypesMsg = new UpdatePersonSignalTypes.Message()
                {
                    PersonIds = people
                };

                updatePersonSignalTypesMsg.Send();
            }

            NavigateToParentPage();
        }
Пример #3
0
        /// <summary>
        /// Handles the GridReorder event of the gPersonSignalType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs" /> instance containing the event data.</param>
        void gPersonSignalType_GridReorder(object sender, GridReorderEventArgs e)
        {
            var rockContext = new RockContext();
            var service     = new SignalTypeService(rockContext);
            var signalTypes = service.Queryable().OrderBy(b => b.Order);

            service.Reorder(signalTypes.ToList(), e.OldIndex, e.NewIndex);
            rockContext.SaveChanges();

            BindGrid();
        }
Пример #4
0
        /// <summary>
        /// Handles the Delete event of the gPersonSignalType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gPersonSignalType_Delete(object sender, RowEventArgs e)
        {
            var rockContext       = new RockContext();
            var signalTypeService = new SignalTypeService(rockContext);
            var signalType        = signalTypeService.Get(e.RowKeyId);

            if (signalType != null)
            {
                string errorMessage;
                if (!signalTypeService.CanDelete(signalType, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                var people = new PersonSignalService(rockContext).Queryable()
                             .Where(s => s.SignalTypeId == signalType.Id)
                             .Select(s => s.PersonId)
                             .Distinct()
                             .ToList();

                signalTypeService.Delete(signalType);
                rockContext.SaveChanges();

                //
                // If less than 250 people with this signal type then just update them all now,
                // otherwise put something in the rock queue to take care of it.
                //
                if (people.Count < 250)
                {
                    new PersonService(rockContext).Queryable()
                    .Where(p => people.Contains(p.Id))
                    .ToList()
                    .ForEach(p => p.CalculateSignals());

                    rockContext.SaveChanges();
                }
                else
                {
                    var updatePersonSignalTypesMsg = new UpdatePersonSignalTypes.Message
                    {
                        PersonIds = people
                    };
                    updatePersonSignalTypesMsg.Send();
                }
            }

            BindGrid();
        }
Пример #5
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result = "Person Signal";

            string[] selectionValues = selection.Split('|');

            if (selectionValues.Length >= 1)
            {
                int signalTypeId       = selectionValues[0].AsInteger();
                var selectedSignalType = new SignalTypeService(new RockContext()).Get(signalTypeId);

                if (selectedSignalType != null)
                {
                    result = string.Format("Has a {0} signal", selectedSignalType.Name);
                }
                else
                {
                    result = "Has a signal";
                }
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Shows all the edit details for this signal type.
        /// </summary>
        private void ShowDetail()
        {
            var rockContext = new RockContext();
            var signalType  = new SignalTypeService(rockContext).Get(SignalTypeId);

            if (signalType == null)
            {
                signalType             = new SignalType();
                pdAuditDetails.Visible = false;
                lActionTitle.Text      = ActionTitle.Add(signalType.Name).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = ActionTitle.Edit(signalType.Name).FormatAsHtmlTitle();
            }

            //
            // Switch everything to read-only if user not allowed to administrate.
            //
            if (!signalType.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson) || !IsUserAuthorized(Authorization.EDIT))
            {
                tbName.Enabled         = false;
                tbDescription.Enabled  = false;
                cpColor.Enabled        = false;
                tbIconCssClass.Enabled = false;

                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit(SignalType.FriendlyTypeName);
            }

            tbName.Text         = signalType.Name;
            tbDescription.Text  = signalType.Description;
            cpColor.Text        = signalType.SignalColor;
            tbIconCssClass.Text = signalType.SignalIconCssClass;

            pdAuditDetails.SetEntity(signalType, ResolveRockUrl("~"));
        }