public static void AddMoveHistory(RockContext rockContext, Location location, Attendance attendeeAttendance, bool isSubroom)
        {
            var moveSummary = string.Format("{0}</span> at <span class=\"field-name\">{1}", location.Name, Rock.RockDateTime.Now);

            if (isSubroom)
            {
                moveSummary += string.Format("</span> (a subroom of <span class=\"field-name\">{0})", location.ParentLocation.Name);
            }

            var changes = new History.HistoryChangeList();

            changes.AddCustom("Entry", History.HistoryChangeType.Record.ToString(), moveSummary.Truncate(250));
            changes.First().Caption             = "Moved To Location";
            changes.First().RelatedEntityTypeId = locationEntityTypeId;
            changes.First().RelatedEntityId     = location.Id;
            changes.First().RelatedData         = GetHostInfo();

            HistoryService.SaveChanges(
                rockContext,
                typeof(Rock.Model.Person),
                CategoryCache.Get(4).Guid,
                attendeeAttendance.PersonAlias.PersonId,
                changes,
                true
                );
        }
        public static void AddWithParentHistory(RockContext rockContext, Person person)
        {
            var summary = string.Format("</span> to be with Parent at <span class=\"field-name\">{0}", Rock.RockDateTime.Now);

            var changes = new History.HistoryChangeList();

            changes.AddCustom("Moved", History.HistoryChangeType.Record.ToString(), summary.Truncate(250));
            changes.First().Caption     = "Moved be with Parent";
            changes.First().RelatedData = GetHostInfo();

            HistoryService.SaveChanges(
                rockContext,
                typeof(Rock.Model.Person),
                CategoryCache.Get(4).Guid,
                person.Id,
                changes,
                true
                );
            AttendanceCache.SetWithParent(person.Id);
        }
Exemple #3
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var personGuid = GetAttributeValue(action, "Person", true).AsGuidOrNull();

            if (personGuid == null)
            {
                errorMessages.Add("Person Add History requires a valid person");
                return(false);
            }

            var categoryGuid = GetAttributeValue(action, "Category").AsGuid();
            var category     = new CategoryService(rockContext).Get(categoryGuid);

            if (category == null)
            {
                errorMessages.Add("Person Add History requires a valid category");
                return(false);
            }

            PersonAliasService personAliasService = new PersonAliasService(rockContext);
            var personAlias = personAliasService.Get(personGuid.Value);

            if (personAlias != null)
            {
                var person               = personAlias.Person;
                var entityTypeId         = EntityTypeCache.GetId(typeof(Rock.Model.Person));
                var workflowEntityTypeId = EntityTypeCache.GetId(typeof(Rock.Model.Workflow));
                var mergeFields          = GetMergeFields(action);
                var caption              = GetAttributeValue(action, "Caption").ResolveMergeFields(mergeFields);
                var summary              = GetAttributeValue(action, "Summary").ResolveMergeFields(mergeFields);
                var verb = GetAttributeValue(action, "Verb").ResolveMergeFields(mergeFields);


                var personChanges = new History.HistoryChangeList();

                personChanges.AddCustom(verb, History.HistoryChangeType.Record.ToString(), summary.Truncate(250));
                personChanges.First().Caption = caption;

                if (action?.Activity?.Workflow != null && action.Activity.WorkflowId != 0)
                {
                    personChanges.First().RelatedEntityTypeId = workflowEntityTypeId;
                    personChanges.First().RelatedEntityId     = action.Activity.WorkflowId;
                }

                HistoryService.SaveChanges(
                    rockContext,
                    typeof(Rock.Model.Person),
                    category.Guid,
                    person.Id,
                    personChanges,
                    true
                    );

                return(true);
            }
            else
            {
                errorMessages.Add("Person Add History requires a valid person");
                return(false);
            }
        }