/// <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(); }
/// <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(); }