public GetPerson ( System.Guid personAliasGuid ) : Person | ||
personAliasGuid | System.Guid | The person alias unique identifier. |
return | Person |
/// <summary> /// Gets the person entry people that should be used for this action. /// </summary> /// <param name="rockContext">The rock context to use with database operations.</param> /// <param name="currentPersonId">The currently logged in person identifier.</param> /// <param name="personEntryPerson">On return will contain the <see cref="Person"/> object to be used for this form.</param> /// <param name="personEntrySpouse">On return will contain the <see cref="Person"/> object to be used for this form..</param> public void GetPersonEntryPeople(RockContext rockContext, int?currentPersonId, out Person personEntryPerson, out Person personEntrySpouse) { personEntryPerson = null; personEntrySpouse = null; var workflowType = ActionTypeCache?.ActivityType?.WorkflowType; if (workflowType == null) { return; } var personEntrySettings = ActionTypeCache.WorkflowForm?.GetFormPersonEntrySettings(workflowType.FormBuilderTemplate); if (personEntrySettings == null) { return; } if (personEntrySettings.AutofillCurrentPerson && currentPersonId.HasValue) { var personService = new PersonService(rockContext); personEntryPerson = personService.Get(currentPersonId.Value); personEntrySpouse = personEntryPerson.GetSpouse(); } else { AttributeCache personEntryPersonAttribute = ActionTypeCache.WorkflowForm?.GetPersonEntryPersonAttribute(Activity.Workflow); AttributeCache personEntrySpouseAttribute = ActionTypeCache.WorkflowForm?.GetPersonEntrySpouseAttribute(Activity.Workflow); // Not using the current person, so initialize with the current value of PersonEntryPersonAttributeGuid (normally this would be null unless then also had a PersonEntry form on previous Activities) if (personEntryPersonAttribute != null) { var personAliasGuid = GetWorkflowAttributeValue(personEntryPersonAttribute.Guid).AsGuidOrNull(); if (personAliasGuid.HasValue) { // the workflow already set a value for the FormEntry person, so use that var personAliasService = new PersonAliasService(rockContext); personEntryPerson = personAliasService.GetPerson(personAliasGuid.Value); } } // Not using the current person, so initialize with the current value PersonEntrySpouseAttributeGuid (normally this would be null unless then also had a PersonEntry form on previous Activities) if (personEntrySpouseAttribute != null) { var spousePersonAliasGuid = GetWorkflowAttributeValue(personEntrySpouseAttribute.Guid).AsGuidOrNull(); if (spousePersonAliasGuid.HasValue) { // the workflow already set a value for the FormEntry person, so use that var personAliasService = new PersonAliasService(rockContext); personEntrySpouse = personAliasService.GetPerson(spousePersonAliasGuid.Value); } } } }
/// <summary> /// Gets the person entry people that should be used for this action. /// </summary> /// <param name="rockContext">The rock context to use with database operations.</param> /// <param name="currentPersonId">The currently logged in person identifier.</param> /// <param name="personEntryPerson">On return will contain the <see cref="Person"/> object to be used for this form.</param> /// <param name="personEntrySpouse">On return will contain the <see cref="Person"/> object to be used for this form..</param> public void GetPersonEntryPeople(RockContext rockContext, int?currentPersonId, out Person personEntryPerson, out Person personEntrySpouse) { personEntryPerson = null; personEntrySpouse = null; var form = ActionTypeCache.WorkflowForm; if (form == null) { return; } if (form.PersonEntryAutofillCurrentPerson && currentPersonId.HasValue) { var personService = new PersonService(rockContext); personEntryPerson = personService.Get(currentPersonId.Value); personEntrySpouse = personEntryPerson.GetSpouse(); } else { // Not using the current person, so initialize with the current value of PersonEntryPersonAttributeGuid (normally this would be null unless then also had a PersonEntry form on previous Activities) if (form.PersonEntryPersonAttributeGuid.HasValue) { var personAliasGuid = GetWorkflowAttributeValue(form.PersonEntryPersonAttributeGuid.Value).AsGuidOrNull(); if (personAliasGuid.HasValue) { // the workflow already set a value for the FormEntry person, so use that var personAliasService = new PersonAliasService(rockContext); personEntryPerson = personAliasService.GetPerson(personAliasGuid.Value); } } // Not using the current person, so initialize with the current value PersonEntrySpouseAttributeGuid (normally this would be null unless then also had a PersonEntry form on previous Activities) if (form.PersonEntrySpouseAttributeGuid.HasValue) { var spousePersonAliasGuid = GetWorkflowAttributeValue(form.PersonEntrySpouseAttributeGuid.Value).AsGuidOrNull(); if (spousePersonAliasGuid.HasValue) { // the workflow already set a value for the FormEntry person, so use that var personAliasService = new PersonAliasService(rockContext); personEntrySpouse = personAliasService.GetPerson(spousePersonAliasGuid.Value); } } } }
/// <summary> /// Saves the person notes. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="previousRegistrantIds">The previous registrants.</param> /// <param name="registration">The registration.</param> private void SavePersonNotes( RockContext rockContext, List<int> previousRegistrantIds, Registration registration ) { // Setup Note settings NoteTypeCache noteType = null; if ( RegistrationTemplate != null && RegistrationTemplate.AddPersonNote ) { noteType = NoteTypeCache.Read( 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 registrant = personAliasService.GetPerson( registrantPersonAliasId ); if ( registrant != null && !previousRegistrantIds.Contains( registrant.Id ) ) { var noteText = new StringBuilder(); noteText.AppendFormat( "Registered for {0}", RegistrationInstanceState.Name ); if ( registrar != null && registrar.Id != registrant.Id ) { noteText.AppendFormat( " by {0}", registrar.FullName ); registrantNames.Add( registrant.FullName ); } if ( registrar != null && ( RegistrationState.FirstName != registrar.NickName || RegistrationState.LastName != registrar.LastName ) ) { noteText.AppendFormat( " by {0}", RegistrationState.FirstName + " " + RegistrationState.LastName ); } if ( noteText.Length > 0 ) { var note = new Note(); note.NoteTypeId = noteType.Id; note.IsSystem = false; note.IsAlert = false; note.IsPrivateNote = false; note.EntityId = registrant.Id; note.Caption = string.Empty; note.Text = noteText.ToString(); noteService.Add( note ); } var changes = new List<string> { "Registered for" }; HistoryService.SaveChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(), registrant.Id, changes, RegistrationInstanceState.Name, typeof( Registration ), registration.Id, false, registration.PersonAliasId ); } } 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, RegistrationInstanceState.Name ); noteService.Add( note ); var changes = new List<string> { string.Format( "Registered {0} for", namesText ) }; HistoryService.SaveChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(), registrar.Id, changes, RegistrationInstanceState.Name, typeof( Registration ), registration.Id, false, registration.PersonAliasId ); } rockContext.SaveChanges(); } } }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { using ( var rockContext = new RockContext() ) { var documentService = new SignatureDocumentService( rockContext ); var personAliasService = new PersonAliasService( rockContext ); var appliesPerson = personAliasService.GetPerson( AppliesToPersonAliasId ); var assignedPerson = personAliasService.GetPerson( AssignedToPersonAliasId ); if ( !documentService.Queryable().Any( d => d.AppliesToPersonAliasId.HasValue && d.AppliesToPersonAliasId.Value == AppliesToPersonAliasId && d.Status == SignatureDocumentStatus.Signed ) ) { var documentTypeService = new SignatureDocumentTemplateService( rockContext ); var SignatureDocumentTemplate = documentTypeService.Get( SignatureDocumentTemplateId ); var errorMessages = new List<string>(); if ( documentTypeService.SendDocument( SignatureDocumentTemplate, appliesPerson, assignedPerson, DocumentName, Email, out errorMessages ) ) { rockContext.SaveChanges(); } } } }
/// <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(); } } } }