예제 #1
0
        /// <summary>
        /// Handles the SaveClick event of the mdEditSignal 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 mdEditSignal_SaveClick(object sender, EventArgs e)
        {
            var          rockContext         = new RockContext();
            var          personSignalService = new PersonSignalService(rockContext);
            PersonSignal signal = null;

            if (hfEditSignalId.Value.AsInteger() != 0)
            {
                signal = personSignalService.Get(hfEditSignalId.Value.AsInteger());
            }
            else
            {
                signal = new PersonSignal
                {
                    PersonId           = Person.Id,
                    OwnerPersonAliasId = CurrentPersonAliasId.Value
                };
                personSignalService.Add(signal);
            }

            signal.SignalTypeId   = ddlSignalType.SelectedValue.AsInteger();
            signal.ExpirationDate = dpExpirationDate.SelectedDate;
            signal.Note           = tbNote.Text;

            rockContext.SaveChanges();

            var person = new PersonService(rockContext).Get(Person.Id);

            person.CalculateSignals();
            rockContext.SaveChanges();

            mdEditSignal.Hide();
            BindGrid();
        }
예제 #2
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var queryable = new PersonSignalService(new RockContext())
                            .Queryable()
                            .Where(s => s.PersonId == Person.Id);

            gSignal.ObjectList = new Dictionary <string, object>();
            queryable.ToList().ForEach(s => gSignal.ObjectList.Add(s.Id.ToString(), s));

            var gridList = queryable.ToList().Select(a =>
                                                     new
            {
                a.Id,
                a.SignalType.Order,
                a.SignalType.Name,
                a.OwnerPersonAlias,
                Note           = a.IsAuthorized(Authorization.VIEW, CurrentPerson) ? a.Note : string.Empty,
                ExpirationDate = a.IsAuthorized(Authorization.VIEW, CurrentPerson) ? a.ExpirationDate : null
            }).AsQueryable();

            if (gSignal.SortProperty != null)
            {
                gSignal.DataSource = gridList.Sort(gSignal.SortProperty).ToList();
            }
            else
            {
                gSignal.DataSource = gridList.OrderBy(s => s.Order).ThenBy(s => s.Id).ToList();
            }

            gSignal.EntityTypeId = EntityTypeCache.Get <Rock.Model.Device>().Id;
            gSignal.DataBind();
        }
예제 #3
0
        /// <summary>
        /// Handles the Delete event of the gSignal 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 gSignal_Delete(object sender, RowEventArgs e)
        {
            var rockContext         = new RockContext();
            var personSignalService = new PersonSignalService(rockContext);
            var person = new PersonService(rockContext).Get(Person.Id);
            var signal = person.Signals.Where(s => s.Id == e.RowKeyId).FirstOrDefault();

            if (signal != null)
            {
                if (!signal.IsAuthorized(Authorization.EDIT, CurrentPerson))
                {
                    mdGridWarning.Show("Not authorized to make changes to this signal.", ModalAlertType.Information);
                    return;
                }

                string errorMessage;
                if (!personSignalService.CanDelete(signal, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                personSignalService.Delete(signal);

                person.CalculateSignals();
                rockContext.SaveChanges();
            }

            BindGrid();
        }
예제 #4
0
        /// <summary>
        /// Handles the Edit event of the gSignal 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 gSignal_Edit(object sender, RowEventArgs e)
        {
            var signal = new PersonSignalService(new RockContext()).Get(e.RowKeyId);

            if (!signal.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                mdGridWarning.Show("Not authorized to make changes to this signal.", ModalAlertType.Information);
                return;
            }

            ddlSignalType.Items.Clear();
            ddlSignalType.Items.Add(new ListItem());

            new SignalTypeService(new RockContext()).Queryable()
            .ToList()
            .Where(t => t.IsAuthorized(Authorization.EDIT, CurrentPerson))
            .OrderBy(t => t.Order)
            .ThenBy(t => t.Id)
            .ToList()
            .ForEach(t => ddlSignalType.Items.Add(new ListItem(t.Name, t.Id.ToString())));

            ddlSignalType.SelectedValue   = signal.SignalTypeId.ToString();
            dpExpirationDate.SelectedDate = signal.ExpirationDate;
            tbNote.Text = signal.Note;
            ppSignalOwner.SetValue(signal.OwnerPersonAlias.Person);
            hfEditSignalId.Value = signal.Id.ToString();

            mdEditSignal.Title = "Edit Signal";
            mdEditSignal.Show();
        }
예제 #5
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();
        }
예제 #6
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();
        }
예제 #7
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(IJobExecutionContext context)
        {
            List <int> people;
            int        count = 0;

            //
            // Create a list of every Person Id that has a signal.
            //
            using (var rockContext = new RockContext())
            {
                people = new PersonSignalService(rockContext).Queryable()
                         .Select(s => s.PersonId)
                         .Distinct()
                         .ToList();
            }

            //
            // Operate in batches of 250 so we don't lag the context too much.
            //
            while (people.Any())
            {
                var batch = people.Take(250).ToList();
                people.RemoveRange(0, batch.Count);

                using (var rockContext = new RockContext())
                {
                    new PersonService(rockContext).Queryable()
                    .Where(p => batch.Contains(p.Id))
                    .ToList()
                    .ForEach(p => p.CalculateSignals());

                    rockContext.SaveChanges();

                    count += batch.Count;
                }
            }

            context.Result = string.Format("{0} people processed", count);
        }
예제 #8
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 1)
            {
                int signalTypeId = selectionValues[0].AsInteger();

                var signalQry = new PersonSignalService(( RockContext )serviceInstance.Context).Queryable();

                if (signalTypeId != 0)
                {
                    signalQry = signalQry.Where(x => x.SignalTypeId == signalTypeId);
                }

                var qry = new PersonService(( RockContext )serviceInstance.Context).Queryable()
                          .Where(p => signalQry.Any(x => x.PersonId == p.Id));

                return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"));
            }

            return(null);
        }