Esempio n. 1
0
        public void RegistrationCreatedDateKeyWorksWithNullValue()
        {
            var registration = new Rock.Model.Registration();

            registration.CreatedDateTime = null;
            Assert.IsNull(registration.CreatedDateKey);
        }
Esempio n. 2
0
        private Rock.Model.Registration BuildRegistration(RockContext rockContext, DateTime?requestDate)
        {
            var registrationInstance = new RegistrationInstanceService(rockContext).Queryable().First();
            var registration         = new Rock.Model.Registration();

            registration.RegistrationInstanceId = registrationInstance.Id;
            registration.ForeignKey             = registrationForiegnKey;
            registration.CreatedDateTime        = requestDate;

            return(registration);
        }
Esempio n. 3
0
        public void RegistrationCreatedDateKeyGetsSetCorrectly()
        {
            var testList = TestDataHelper.GetAnalyticsSourceDateTestData();

            foreach (var keyValue in testList)
            {
                var registration = new Rock.Model.Registration();
                registration.CreatedDateTime = keyValue.Value;
                Assert.AreEqual(keyValue.Key, registration.CreatedDateKey);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Saves the person notes and history.
        /// </summary>
        /// <param name="registrationPersonFirstName">First name of the registration person.</param>
        /// <param name="registrationPersonLastName">Last name of the registration person.</param>
        /// <param name="currentPersonAliasId">The current person alias identifier.</param>
        /// <param name="previousRegistrantPersonIds">The previous registrant person ids.</param>
        public void SavePersonNotesAndHistory(string registrationPersonFirstName, string registrationPersonLastName, int?currentPersonAliasId, List <int> previousRegistrantPersonIds)
        {
            // Setup Note settings
            Registration  registration = this;
            NoteTypeCache noteType     = null;

            using (RockContext rockContext = new RockContext())
            {
                RegistrationInstance registrationInstance = registration.RegistrationInstance ?? new RegistrationInstanceService(rockContext).Get(registration.RegistrationInstanceId);
                RegistrationTemplate registrationTemplate = registrationInstance.RegistrationTemplate ?? new RegistrationTemplateService(rockContext).Get(registrationInstance.RegistrationTemplateId);

                if (registrationTemplate != null && registrationTemplate.AddPersonNote)
                {
                    noteType = NoteTypeCache.Get(Rock.SystemGuid.NoteType.PERSON_EVENT_REGISTRATION.AsGuid());
                    if (noteType != null)
                    {
                        var noteService        = new NoteService(rockContext);
                        var personAliasService = new PersonAliasService(rockContext);

                        Person registrar = null;
                        if (registration.PersonAliasId.HasValue)
                        {
                            registrar = personAliasService.GetPerson(registration.PersonAliasId.Value);
                        }

                        var registrantNames = new List <string>();

                        // Get each registrant
                        foreach (var registrantPersonAliasId in registration.Registrants
                                 .Where(r => r.PersonAliasId.HasValue)
                                 .Select(r => r.PersonAliasId.Value)
                                 .ToList())
                        {
                            var registrantPerson = personAliasService.GetPerson(registrantPersonAliasId);
                            if (registrantPerson != null && (previousRegistrantPersonIds == null || !previousRegistrantPersonIds.Contains(registrantPerson.Id)))
                            {
                                var noteText = new StringBuilder();
                                noteText.AppendFormat("Registered for {0}", registrationInstance.Name);

                                string registrarFullName = string.Empty;

                                if (registrar != null && registrar.Id != registrantPerson.Id)
                                {
                                    registrarFullName = string.Format(" by {0}", registrar.FullName);
                                    registrantNames.Add(registrantPerson.FullName);
                                }

                                if (registrar != null && (registrationPersonFirstName != registrar.NickName || registrationPersonLastName != registrar.LastName))
                                {
                                    registrarFullName = string.Format(" by {0}", registrationPersonFirstName + " " + registrationPersonLastName);
                                }

                                noteText.Append(registrarFullName);

                                if (noteText.Length > 0)
                                {
                                    var note = new Note();
                                    note.NoteTypeId    = noteType.Id;
                                    note.IsSystem      = false;
                                    note.IsAlert       = false;
                                    note.IsPrivateNote = false;
                                    note.EntityId      = registrantPerson.Id;
                                    note.Caption       = string.Empty;
                                    note.Text          = noteText.ToString();
                                    if (registrar == null)
                                    {
                                        note.CreatedByPersonAliasId = currentPersonAliasId;
                                    }
                                    else
                                    {
                                        note.CreatedByPersonAliasId = registrar.PrimaryAliasId;
                                    }

                                    noteService.Add(note);
                                }

                                var changes = new History.HistoryChangeList();
                                changes.AddChange(History.HistoryVerb.Registered, History.HistoryChangeType.Record, null);
                                HistoryService.SaveChanges(
                                    rockContext,
                                    typeof(Person),
                                    Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(),
                                    registrantPerson.Id,
                                    changes,
                                    registrationInstance.Name,
                                    typeof(Registration),
                                    registration.Id,
                                    false,
                                    currentPersonAliasId,
                                    rockContext.SourceOfChange);
                            }
                        }

                        if (registrar != null && registrantNames.Any())
                        {
                            string namesText = string.Empty;
                            if (registrantNames.Count >= 2)
                            {
                                int lessOne = registrantNames.Count - 1;
                                namesText = registrantNames.Take(lessOne).ToList().AsDelimited(", ") +
                                            " and " +
                                            registrantNames.Skip(lessOne).Take(1).First() + " ";
                            }
                            else
                            {
                                namesText = registrantNames.First() + " ";
                            }

                            var note = new Note();
                            note.NoteTypeId    = noteType.Id;
                            note.IsSystem      = false;
                            note.IsAlert       = false;
                            note.IsPrivateNote = false;
                            note.EntityId      = registrar.Id;
                            note.Caption       = string.Empty;
                            note.Text          = string.Format("Registered {0} for {1}", namesText, registrationInstance.Name);
                            noteService.Add(note);

                            var changes = new History.HistoryChangeList();
                            changes.AddChange(History.HistoryVerb.Registered, History.HistoryChangeType.Record, namesText);

                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(Person),
                                Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(),
                                registrar.Id,
                                changes,
                                registrationInstance.Name,
                                typeof(Registration),
                                registration.Id,
                                false,
                                currentPersonAliasId,
                                rockContext.SourceOfChange);
                        }

                        rockContext.SaveChanges();
                    }
                }
            }
        }