Пример #1
0
 /// <summary>
 /// Copies the properties from another RegistrationTemplate object to this RegistrationTemplate object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this RegistrationTemplate target, RegistrationTemplate source)
 {
     target.Id            = source.Id;
     target.AddPersonNote = source.AddPersonNote;
     target.AllowExternalRegistrationUpdates = source.AllowExternalRegistrationUpdates;
     target.AllowGroupPlacement      = source.AllowGroupPlacement;
     target.AllowMultipleRegistrants = source.AllowMultipleRegistrants;
     target.BatchNamePrefix          = source.BatchNamePrefix;
     target.CategoryId = source.CategoryId;
     target.ConfirmationEmailTemplate = source.ConfirmationEmailTemplate;
     target.ConfirmationFromEmail     = source.ConfirmationFromEmail;
     target.ConfirmationFromName      = source.ConfirmationFromName;
     target.ConfirmationSubject       = source.ConfirmationSubject;
     target.Cost                                = source.Cost;
     target.DiscountCodeTerm                    = source.DiscountCodeTerm;
     target.FeeTerm                             = source.FeeTerm;
     target.FinancialGatewayId                  = source.FinancialGatewayId;
     target.ForeignGuid                         = source.ForeignGuid;
     target.ForeignKey                          = source.ForeignKey;
     target.GroupMemberRoleId                   = source.GroupMemberRoleId;
     target.GroupMemberStatus                   = source.GroupMemberStatus;
     target.GroupTypeId                         = source.GroupTypeId;
     target.IsActive                            = source.IsActive;
     target.LoginRequired                       = source.LoginRequired;
     target.MaxRegistrants                      = source.MaxRegistrants;
     target.MinimumInitialPayment               = source.MinimumInitialPayment;
     target.Name                                = source.Name;
     target.Notify                              = source.Notify;
     target.PaymentReminderEmailTemplate        = source.PaymentReminderEmailTemplate;
     target.PaymentReminderFromEmail            = source.PaymentReminderFromEmail;
     target.PaymentReminderFromName             = source.PaymentReminderFromName;
     target.PaymentReminderSubject              = source.PaymentReminderSubject;
     target.PaymentReminderTimeSpan             = source.PaymentReminderTimeSpan;
     target.RegistrantsSameFamily               = source.RegistrantsSameFamily;
     target.RegistrantTerm                      = source.RegistrantTerm;
     target.RegistrationTerm                    = source.RegistrationTerm;
     target.RegistrationWorkflowTypeId          = source.RegistrationWorkflowTypeId;
     target.ReminderEmailTemplate               = source.ReminderEmailTemplate;
     target.ReminderFromEmail                   = source.ReminderFromEmail;
     target.ReminderFromName                    = source.ReminderFromName;
     target.ReminderSubject                     = source.ReminderSubject;
     target.RequestEntryName                    = source.RequestEntryName;
     target.RequiredSignatureDocumentTemplateId = source.RequiredSignatureDocumentTemplateId;
     target.SetCostOnInstance                   = source.SetCostOnInstance;
     target.ShowCurrentFamilyMembers            = source.ShowCurrentFamilyMembers;
     target.SignatureDocumentAction             = source.SignatureDocumentAction;
     target.SuccessText                         = source.SuccessText;
     target.SuccessTitle                        = source.SuccessTitle;
     target.WaitListEnabled                     = source.WaitListEnabled;
     target.WaitListTransitionEmailTemplate     = source.WaitListTransitionEmailTemplate;
     target.WaitListTransitionFromEmail         = source.WaitListTransitionFromEmail;
     target.WaitListTransitionFromName          = source.WaitListTransitionFromName;
     target.WaitListTransitionSubject           = source.WaitListTransitionSubject;
     target.CreatedDateTime                     = source.CreatedDateTime;
     target.ModifiedDateTime                    = source.ModifiedDateTime;
     target.CreatedByPersonAliasId              = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId             = source.ModifiedByPersonAliasId;
     target.Guid                                = source.Guid;
     target.ForeignId                           = source.ForeignId;
 }
Пример #2
0
 /// <summary>
 /// Clones this RegistrationTemplate object to a new RegistrationTemplate object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static RegistrationTemplate Clone(this RegistrationTemplate source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as RegistrationTemplate);
     }
     else
     {
         var target = new RegistrationTemplate();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the options that should be available for additional registrants to specify the family they belong to
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="currentRegistrantIndex">Index of the current registrant.</param>
        /// <returns></returns>
        public Dictionary <Guid, string> GetFamilyOptions(RegistrationTemplate template, int currentRegistrantIndex)
        {
            // Return a dictionary of family group guid, and the formated name (i.e. "Ted & Cindy Decker" )
            var result = new Dictionary <Guid, string>();

            // Get all the registrants prior to the current registrant
            var familyRegistrants = new Dictionary <Guid, List <RegistrantInfo> >();

            for (int i = 0; i < currentRegistrantIndex; i++)
            {
                if (Registrants != null && Registrants.Count > i)
                {
                    var registrant = Registrants[i];
                    familyRegistrants.AddOrIgnore(registrant.FamilyGuid, new List <RegistrantInfo>());
                    familyRegistrants[registrant.FamilyGuid].Add(registrant);
                }
                else
                {
                    break;
                }
            }

            // Loop through those registrants
            foreach (var keyVal in familyRegistrants)
            {
                // Find all the people and group them by same last name
                var lastNames = new Dictionary <string, List <string> >();
                foreach (var registrant in keyVal.Value)
                {
                    string firstName = registrant.GetFirstName(template);
                    string lastName  = registrant.GetLastName(template);
                    lastNames.AddOrIgnore(lastName, new List <string>());
                    lastNames[lastName].Add(firstName);
                }

                // Build a formated output for each unique last name
                var familyNames = new List <string>();
                foreach (var lastName in lastNames)
                {
                    familyNames.Add(string.Format("{0} {1}", lastName.Value.AsDelimited(" & "), lastName.Key));
                }

                // Join each of the formated values for each unique last name for the current family
                result.Add(keyVal.Key, familyNames.AsDelimited(" and "));
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Gets a person field value.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="personFieldType">Type of the person field.</param>
        /// <returns></returns>
        public object GetPersonFieldValue(RegistrationTemplate template, RegistrationPersonFieldType personFieldType)
        {
            if (template != null && template.Forms != null)
            {
                var fieldId = template.Forms
                              .SelectMany(t => t.Fields
                                          .Where(f =>
                                                 f.FieldSource == RegistrationFieldSource.PersonField &&
                                                 f.PersonFieldType == personFieldType)
                                          .Select(f => f.Id))
                              .FirstOrDefault();

                return(FieldValues.ContainsKey(fieldId) ? FieldValues[fieldId].FieldValue : null);
            }

            return(null);
        }
Пример #5
0
        /// <summary>
        /// Gets the email.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <returns></returns>
        public string GetEmail(RegistrationTemplate template)
        {
            object value = GetPersonFieldValue(template, RegistrationPersonFieldType.Email);

            if (value == null)
            {
                // if Email isn't prompted for in a registration form, and using an existing Person, get the person's email from the database
                if (this.PersonId.HasValue)
                {
                    return(new PersonService(new RockContext()).GetSelect(this.PersonId.Value, s => s.Email) ?? string.Empty);
                }
            }
            else
            {
                return(value.ToString());
            }

            return(string.Empty);
        }
 /// <summary>
 /// Copies the properties from another RegistrationTemplate object to this RegistrationTemplate object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this RegistrationTemplate target, RegistrationTemplate source)
 {
     target.Id                        = source.Id;
     target.AddPersonNote             = source.AddPersonNote;
     target.AllowMultipleRegistrants  = source.AllowMultipleRegistrants;
     target.CategoryId                = source.CategoryId;
     target.ConfirmationEmailTemplate = source.ConfirmationEmailTemplate;
     target.ConfirmationFromEmail     = source.ConfirmationFromEmail;
     target.ConfirmationFromName      = source.ConfirmationFromName;
     target.ConfirmationSubject       = source.ConfirmationSubject;
     target.Cost                      = source.Cost;
     target.DiscountCodeTerm          = source.DiscountCodeTerm;
     target.FeeTerm                   = source.FeeTerm;
     target.FinancialGatewayId        = source.FinancialGatewayId;
     target.ForeignGuid               = source.ForeignGuid;
     target.ForeignKey                = source.ForeignKey;
     target.GroupMemberRoleId         = source.GroupMemberRoleId;
     target.GroupMemberStatus         = source.GroupMemberStatus;
     target.GroupTypeId               = source.GroupTypeId;
     target.IsActive                  = source.IsActive;
     target.LoginRequired             = source.LoginRequired;
     target.MaxRegistrants            = source.MaxRegistrants;
     target.MinimumInitialPayment     = source.MinimumInitialPayment;
     target.Name                      = source.Name;
     target.Notify                    = source.Notify;
     target.RegistrantsSameFamily     = source.RegistrantsSameFamily;
     target.RegistrantTerm            = source.RegistrantTerm;
     target.RegistrationTerm          = source.RegistrationTerm;
     target.ReminderEmailTemplate     = source.ReminderEmailTemplate;
     target.ReminderFromEmail         = source.ReminderFromEmail;
     target.ReminderFromName          = source.ReminderFromName;
     target.ReminderSubject           = source.ReminderSubject;
     target.RequestEntryName          = source.RequestEntryName;
     target.SuccessText               = source.SuccessText;
     target.SuccessTitle              = source.SuccessTitle;
     target.CreatedDateTime           = source.CreatedDateTime;
     target.ModifiedDateTime          = source.ModifiedDateTime;
     target.CreatedByPersonAliasId    = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId   = source.ModifiedByPersonAliasId;
     target.Guid                      = source.Guid;
     target.ForeignId                 = source.ForeignId;
 }
Пример #7
0
        /// <summary>
        /// Gets the email.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <returns></returns>
        public string GetEmail(RegistrationTemplate template)
        {
            object value = GetPersonFieldValue(template, RegistrationPersonFieldType.Email);

            return(value != null?value.ToString() : string.Empty);
        }
 /// <summary>
 /// Applies the additional properties and security to view model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="viewModel">The view model.</param>
 /// <param name="currentPerson">The current person.</param>
 /// <param name="loadAttributes">if set to <c>true</c> [load attributes].</param>
 public override void ApplyAdditionalPropertiesAndSecurityToViewModel(RegistrationTemplate model, RegistrationTemplateViewModel viewModel, Person currentPerson = null, bool loadAttributes = true)
 {
     viewModel.PluralRegistrantTerm = model.RegistrantTerm.Pluralize();
 }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegistrationSettings"/> class.
        /// </summary>
        /// <param name="template">The registration template.</param>
        /// <param name="instance">The registration instance.</param>
        public RegistrationSettings(RegistrationTemplate template, RegistrationInstance instance)
        {
            RegistrationTemplateId = template.Id;
            RegistrationInstanceId = instance.Id;

            // Cost related
            var setCostOnInstance = template.SetCostOnInstance == true;

            PerRegistrantCost = (setCostOnInstance ? instance.Cost : template.Cost) ?? 0;
            PerRegistrantMinInitialPayment     = setCostOnInstance ? instance.MinimumInitialPayment : template.MinimumInitialPayment;
            PerRegistrantDefaultInitialPayment = setCostOnInstance ? instance.DefaultPayment : template.DefaultPayment;

            // Models
            Fees      = template.Fees.ToList();
            Forms     = template.Forms.ToList();
            Discounts = template.Discounts.ToList();

            // Simple properties
            MaxAttendees                     = instance.MaxAttendees;
            IsTimeoutEnabled                 = instance.TimeoutIsEnabled;
            TimeoutMinutes                   = instance.TimeoutIsEnabled ? instance.TimeoutLengthMinutes : null;
            TimeoutThreshold                 = instance.TimeoutIsEnabled ? instance.TimeoutThreshold : null;
            RegistrarOption                  = template.RegistrarOption;
            RegistrantsSameFamily            = template.RegistrantsSameFamily;
            IsWaitListEnabled                = template.WaitListEnabled;
            AreCurrentFamilyMembersShown     = template.ShowCurrentFamilyMembers;
            MaxRegistrants                   = (template.AllowMultipleRegistrants ? template.MaxRegistrants : 1) ?? instance.MaxAttendees;
            IsLoginRequired                  = template.LoginRequired;
            AllowExternalRegistrationUpdates = template.AllowExternalRegistrationUpdates;

            // Workflow type ids
            WorkflowTypeIds = new List <int>();

            if (template.RegistrationWorkflowTypeId.HasValue)
            {
                WorkflowTypeIds.Add(template.RegistrationWorkflowTypeId.Value);
            }

            if (instance.RegistrationWorkflowTypeId.HasValue)
            {
                WorkflowTypeIds.Add(instance.RegistrationWorkflowTypeId.Value);
            }

            RegistrantWorkflowTypeId = template.RegistrantWorkflowTypeId;

            // Terms and text
            Instructions        = instance.RegistrationInstructions.IsNullOrWhiteSpace() ? template.RegistrationInstructions : instance.RegistrationInstructions;
            FeeTerm             = template.FeeTerm.IsNullOrWhiteSpace() ? "Fee" : template.FeeTerm;
            RegistrantTerm      = template.RegistrantTerm.IsNullOrWhiteSpace() ? "Person" : template.RegistrantTerm;
            AttributeTitleStart = template.RegistrationAttributeTitleStart.IsNullOrWhiteSpace() ? "Registration Information" : template.RegistrationAttributeTitleStart;
            AttributeTitleEnd   = template.RegistrationAttributeTitleEnd.IsNullOrWhiteSpace() ? "Registration Information" : template.RegistrationAttributeTitleEnd;
            RegistrationTerm    = template.RegistrationTerm.IsNullOrWhiteSpace() ? "Registration" : template.RegistrationTerm;
            Name = instance.Name.IsNullOrWhiteSpace() ? template.Name : instance.Name;

            // Gateway related
            FinancialGatewayId        = template.FinancialGatewayId;
            ExternalGatewayFundId     = instance.ExternalGatewayFundId;
            ExternalGatewayMerchantId = instance.ExternalGatewayMerchantId;
            FinancialAccountId        = instance.AccountId;
            BatchNamePrefix           = template.BatchNamePrefix;

            // Group placement
            GroupTypeId       = template.GroupTypeId;
            GroupMemberRoleId = template.GroupMemberRoleId;
            GroupMemberStatus = template.GroupMemberStatus;
        }
Пример #10
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();
                    }
                }
            }
        }