/// <summary> /// Goes to the confirmation page with changes. /// </summary> private void GoNext() { var person = GetCurrentPerson(); if (person != null) { var changes = new List <string>(); person.PreSelected = person.Selected; var groupTypes = person.GroupTypes.ToList(); foreach (var groupType in groupTypes) { History.EvaluateChange(changes, string.Format("{0} Grouptype", groupType), groupType.PreSelected, groupType.Selected); groupType.PreSelected = groupType.Selected; } var groups = groupTypes.SelectMany(gt => gt.Groups).ToList(); foreach (var group in groups) { History.EvaluateChange(changes, string.Format("{0} Group", group), group.PreSelected, group.Selected); group.PreSelected = group.Selected; } var locations = groups.SelectMany(g => g.Locations).ToList(); foreach (var location in locations) { History.EvaluateChange(changes, string.Format("{0} Location", location), location.PreSelected, location.Selected); location.PreSelected = location.Selected; } var schedules = locations.SelectMany(l => l.Schedules).ToList(); foreach (var schedule in schedules) { History.EvaluateChange(changes, string.Format("{0} Schedule", schedule), schedule.PreSelected, schedule.Selected); schedule.PreSelected = schedule.Selected; } HistoryService.AddChanges( new RockContext(), typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_ACTIVITY.AsGuid(), person.Person.Id, changes, CurrentPersonAliasId ); } else { maWarning.Show(InvalidParameterError, ModalAlertType.Warning); } SaveState(); NavigateToNextPage(); }
/// <summary> /// Handles the Click event of the btnSubmit 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 btnSubmit_Click(object sender, EventArgs e) { if (_person != null) { var changes = new List <string>(); var rockContext = new RockContext(); var service = new PersonService(rockContext); var person = service.Get(_person.Id); if (person != null) { EmailPreference emailPreference = EmailPreference.EmailAllowed; switch (rblEmailPreference.SelectedValue) { case "1": { emailPreference = EmailPreference.NoMassEmails; break; } case "2": case "3": { emailPreference = EmailPreference.DoNotEmail; break; } } History.EvaluateChange(changes, "Email Preference", person.EmailPreference, emailPreference); person.EmailPreference = emailPreference; if (rblEmailPreference.SelectedValue == "3") { var newRecordStatus = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE); if (newRecordStatus != null) { History.EvaluateChange(changes, "Record Status", DefinedValueCache.GetName(person.RecordStatusValueId), newRecordStatus.Value); person.RecordStatusValueId = newRecordStatus.Id; } var newInactiveReason = DefinedValueCache.Read(ddlInactiveReason.SelectedValue.AsInteger()); if (newInactiveReason != null) { History.EvaluateChange(changes, "Record Status Reason", DefinedValueCache.GetName(person.RecordStatusReasonValueId), newInactiveReason.Value); person.RecordStatusReasonValueId = newInactiveReason.Id; } var newReviewReason = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_REVIEW_REASON_SELF_INACTIVATED); if (newReviewReason != null) { History.EvaluateChange(changes, "Review Reason", DefinedValueCache.GetName(person.ReviewReasonValueId), newReviewReason.Value); person.ReviewReasonValueId = newReviewReason.Id; } // If the inactive reason note is the same as the current review reason note, update it also. if ((person.InactiveReasonNote ?? string.Empty) == (person.ReviewReasonNote ?? string.Empty)) { History.EvaluateChange(changes, "Inactive Reason Note", person.InactiveReasonNote, tbInactiveNote.Text); person.InactiveReasonNote = tbInactiveNote.Text; } History.EvaluateChange(changes, "Review Reason Note", person.ReviewReasonNote, tbInactiveNote.Text); person.ReviewReasonNote = tbInactiveNote.Text; } else { var newRecordStatus = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE); if (newRecordStatus != null) { History.EvaluateChange(changes, "Record Status", DefinedValueCache.GetName(person.RecordStatusValueId), newRecordStatus.Value); person.RecordStatusValueId = newRecordStatus.Id; } History.EvaluateChange(changes, "Record Status Reason", DefinedValueCache.GetName(person.RecordStatusReasonValueId), string.Empty); person.RecordStatusReasonValueId = null; } HistoryService.AddChanges( rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), person.Id, changes, CurrentPersonAliasId); rockContext.SaveChanges(); nbMessage.Visible = true; return; } } }
/// <summary> /// Process the people for their engagement status. /// </summary> /// <param name="personIds">The list of person identifiers that need to be processed.</param> /// <param name="engaged">True if the person is becoming engaged, false if leaving engagement.</param> /// <param name="engagedAttribute">The attribute to store the true/false value of their engagement status.</param> /// <param name="startDateAttribute">The attribute to store the date they became engaged.</param> /// <param name="endDateAttribute">The attribute to store the date they left engagement.</param> /// <param name="workflowType">The workflow type to be launched for each person.</param> protected void ProcessPeople(List <int> personIds, bool engaged, AttributeCache engagedAttribute, AttributeCache startDateAttribute, AttributeCache endDateAttribute, Guid?workflowType) { while (personIds.Any()) { using (var rockContext = new RockContext()) { // // Work in batches so we don't overload the change tracker. // var people = new PersonService(rockContext).Queryable() .Where(p => personIds.Take(BATCH_SIZE).Contains(p.Id)) .ToList(); personIds = personIds.Skip(BATCH_SIZE).ToList(); foreach (var person in people) { var changes = new List <string>(); // // Update person attributes. // if (engagedAttribute != null || startDateAttribute != null || endDateAttribute != null) { person.LoadAttributes(rockContext); // // Always update the Engaged attribute. // if (engagedAttribute != null) { SetPersonAttribute(rockContext, person, engagedAttribute, engaged.ToString(), changes); } // // Update the Start Date attribute only if we are becoming engaged. When leaving // engagement we leave this set so they can see the period of time they were // engaged. // if (startDateAttribute != null && engaged) { SetPersonAttribute(rockContext, person, startDateAttribute, RockDateTime.Now.ToShortDateString(), changes); } // // Always update the End Date attribute. If we are leaving engagement then set the // current date, otherwise make it blank (we are now engaged, so no end date yet). // if (endDateAttribute != null) { SetPersonAttribute(rockContext, person, endDateAttribute, !engaged ? RockDateTime.Now.ToShortDateString() : string.Empty, changes); } } // // Create history records. // if (changes.Any()) { HistoryService.AddChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), person.Id, changes); } } rockContext.SaveChanges(); // // Launch the workflows. // if (workflowType.HasValue) { foreach (var person in people) { person.LaunchWorkflow(workflowType, person.FullName); } } } } }