Exemple #1
0
 /// <summary>
 /// Deletes (detaches) the registration instance placement group.
 /// </summary>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <param name="group">The group.</param>
 public void DeleteRegistrationInstancePlacementGroup(RegistrationInstance registrationInstance, Group group)
 {
     if (this.RelatedEntities.RelatedToSourceEntityAlreadyExists(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement))
     {
         this.RelatedEntities.DeleteRelatedToSourceEntity(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement);
     }
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegistrantInfo" /> class.
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="person">The person.</param>
        public RegistrantInfo(RegistrationInstance registrationInstance, Person person)
            : this()
        {
            if (person != null)
            {
                PersonId = person.Id;

                using (var rockContext = new RockContext())
                {
                    PersonName = person.FullName;
                    var family = person.GetFamilies(rockContext).FirstOrDefault();

                    if (registrationInstance != null &&
                        registrationInstance.RegistrationTemplate != null)
                    {
                        var templateFields = registrationInstance.RegistrationTemplate.Forms
                                             .SelectMany(f => f.Fields)
                                             .Where(f => !f.IsInternal && f.ShowCurrentValue);

                        foreach (var field in templateFields)
                        {
                            object dbValue = GetRegistrantValue(null, person, family, field, rockContext);
                            if (dbValue != null)
                            {
                                FieldValues.Add(field.Id, new FieldValueObject(field, dbValue));
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Copies the properties from another RegistrationInstance object to this RegistrationInstance object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this RegistrationInstance target, RegistrationInstance source)
 {
     target.Id        = source.Id;
     target.AccountId = source.AccountId;
     target.AdditionalConfirmationDetails = source.AdditionalConfirmationDetails;
     target.AdditionalReminderDetails     = source.AdditionalReminderDetails;
     target.ContactEmail         = source.ContactEmail;
     target.ContactPersonAliasId = source.ContactPersonAliasId;
     target.ContactPhone         = source.ContactPhone;
     target.Cost                       = source.Cost;
     target.Details                    = source.Details;
     target.EndDateTime                = source.EndDateTime;
     target.ForeignGuid                = source.ForeignGuid;
     target.ForeignKey                 = source.ForeignKey;
     target.IsActive                   = source.IsActive;
     target.MaxAttendees               = source.MaxAttendees;
     target.MinimumInitialPayment      = source.MinimumInitialPayment;
     target.Name                       = source.Name;
     target.RegistrationTemplateId     = source.RegistrationTemplateId;
     target.RegistrationWorkflowTypeId = source.RegistrationWorkflowTypeId;
     target.ReminderSent               = source.ReminderSent;
     target.SendReminderDateTime       = source.SendReminderDateTime;
     target.StartDateTime              = source.StartDateTime;
     target.CreatedDateTime            = source.CreatedDateTime;
     target.ModifiedDateTime           = source.ModifiedDateTime;
     target.CreatedByPersonAliasId     = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId    = source.ModifiedByPersonAliasId;
     target.Guid                       = source.Guid;
     target.ForeignId                  = source.ForeignId;
 }
Exemple #4
0
        /// <summary>
        /// Adds the registration instance placement group. Returns false if the group is already a placement group for this instance.
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="group">The group.</param>
        /// <returns></returns>
        public bool AddRegistrationInstancePlacementGroup(RegistrationInstance registrationInstance, Group group)
        {
            if (!this.RelatedEntities.RelatedToSourceEntityAlreadyExists(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement))
            {
                this.RelatedEntities.AddRelatedToSourceEntity(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement);
                return(true);
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Adds the fee control.
        /// </summary>
        /// <param name="phFees">The ph fees.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration. Set to NULL if editing a single registrant.</param>
        public void AddFeeControl(PlaceHolder phFees, RegistrationInstance registrationInstance, bool setValues, List <FeeInfo> feeValues, List <RegistrantInfo> otherRegistrants)
        {
            RegistrationTemplateFee fee = this;
            Control feeControl          = null;

            if (fee.FeeType == RegistrationFeeType.Single)
            {
                var feeItem = fee.FeeItems.FirstOrDefault();
                if (feeItem != null)
                {
                    int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);

                    string controlLabel;

                    if (feeItem.Cost != 0.0M)
                    {
                        controlLabel = $"{feeItem.Name} ({feeItem.Cost.FormatAsCurrency()})";
                    }
                    else
                    {
                        controlLabel = feeItem.Name;
                    }

                    if (fee.AllowMultiple)
                    {
                        feeControl = GetFeeSingleOptionMultipleQuantityControl(setValues, controlLabel, feeValues, usageCountRemaining);
                    }
                    else
                    {
                        feeControl = GetFeeSingleOptionSingleQuantityControl(setValues, controlLabel, feeValues, usageCountRemaining);
                    }
                }
            }
            else
            {
                if (fee.AllowMultiple)
                {
                    feeControl = GetFeeMultipleOptionMultipleQuantityControl(setValues, feeValues, registrationInstance, otherRegistrants);
                }
                else
                {
                    feeControl = GetFeeMultipleOptionSingleQuantityControl(setValues, feeValues, registrationInstance, otherRegistrants);
                }
            }

            if (feeControl != null)
            {
                if (feeControl is IHasValidationGroup hasValidationGroup)
                {
                    hasValidationGroup.ValidationGroup = phFees.RockBlock()?.BlockValidationGroup;
                }

                phFees.Controls.Add(feeControl);
            }
        }
        /// <summary>
        /// Adds the registration instance placement group. Returns false if the group is already a placement group for this instance.
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="group">The group.</param>
        /// <param name="registrationTemplatePlacementId">The registration template placement identifier.</param>
        /// <returns></returns>
        public bool AddRegistrationInstancePlacementGroup(RegistrationInstance registrationInstance, Group group, int registrationTemplatePlacementId)
        {
            string qualifierValue = registrationTemplatePlacementId.ToString();

            if (!this.RelatedEntities.RelatedToSourceEntityAlreadyExists(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement, qualifierValue))
            {
                this.RelatedEntities.AddRelatedToSourceEntity(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement, registrationTemplatePlacementId.ToString());
                return(true);
            }

            return(false);
        }
Exemple #7
0
 /// <summary>
 /// Clones this RegistrationInstance object to a new RegistrationInstance 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 RegistrationInstance Clone(this RegistrationInstance source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as RegistrationInstance);
     }
     else
     {
         var target = new RegistrationInstance();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
        /// <summary>
        /// Gets a summary of the registration
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <returns></returns>
        public string GetSummary(RegistrationInstance registrationInstance = null)
        {
            var result = new StringBuilder();

            result.Append("Event registration payment");

            var instance = registrationInstance ?? RegistrationInstance;

            if (instance != null)
            {
                result.AppendFormat(" for {0} [ID:{1}]", instance.Name, instance.Id);
                if (instance.RegistrationTemplate != null)
                {
                    result.AppendFormat(" (Template: {0} [ID:{1}])", instance.RegistrationTemplate.Name, instance.RegistrationTemplate.Id);
                }
            }

            string registrationPerson = PersonAlias != null && PersonAlias.Person != null ?
                                        PersonAlias.Person.FullName :
                                        string.Format("{0} {1}", FirstName, LastName);

            result.AppendFormat(
                @".
Registration By: {0} Total Cost/Fees:{1}
",
                registrationPerson,
                DiscountedCost.FormatAsCurrency());

            var registrantPersons = new List <string>();

            if (Registrants != null)
            {
                foreach (var registrant in Registrants.Where(r => r.PersonAlias != null && r.PersonAlias.Person != null))
                {
                    registrantPersons.Add($"{registrant.PersonAlias.Person.FullName} Cost/Fees:{registrant.DiscountedCost( DiscountPercentage, DiscountAmount ).FormatAsCurrency()}");
                }
            }

            result.AppendFormat("Registrants: {0}", registrantPersons.AsDelimited(", "));

            return(result.ToString());
        }
Exemple #9
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <param name="includeEventItem">if set to <c>true</c> [include event item].</param>
        /// <param name="includeRegistrationInstance">if set to <c>true</c> [include registration instance].</param>
        /// <param name="includeGroup">if set to <c>true</c> [include group].</param>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public string ToString(bool includeEventItem, bool includeRegistrationInstance, bool includeGroup)
        {
            var parts = new List <string>();

            if (includeEventItem && EventItemOccurrence != null)
            {
                parts.Add(EventItemOccurrence.ToString());
            }

            if (includeRegistrationInstance && RegistrationInstance != null)
            {
                parts.Add(RegistrationInstance.ToString());
            }

            if (includeGroup && Group != null)
            {
                parts.Add(Group.ToString());
            }

            return(parts.AsDelimited(" - "));
        }
        /// <summary>
        /// If this fee has a <see cref="MaximumUsageCount" />, returns the number of allowed usages remaining for the specified <see cref="RegistrationInstance" />
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        public int?GetUsageCountRemaining(RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            if (!this.MaximumUsageCount.HasValue || registrationInstance == null)
            {
                return(null);
            }

            int?usageCountRemaining;
            var registrationInstanceId        = registrationInstance.Id;
            var registrationInstanceFeesQuery = new RegistrationRegistrantFeeService(new RockContext()).Queryable().Where(a => a.RegistrationRegistrant.Registration.RegistrationInstanceId == registrationInstanceId);

            var feeUsedCount = registrationInstanceFeesQuery.Where(a => a.RegistrationTemplateFeeItemId == this.Id).Sum(a => ( int? )a.Quantity) ?? 0;

            // get a list of fees that the other registrants in this registrant entry have incurred so far
            List <FeeInfo> otherRegistrantsFees = otherRegistrants?.SelectMany(a => a.FeeValues).Where(a => a.Value != null && a.Key == this.RegistrationTemplateFeeId).SelectMany(a => a.Value).ToList();

            // get the count of fees of this same fee item for other registrants
            int otherRegistrantsUsedCount = otherRegistrantsFees?.Where(a => a.RegistrationTemplateFeeItemId == this.Id).Sum(f => f.Quantity) ?? 0;

            usageCountRemaining = this.MaximumUsageCount.Value - feeUsedCount - otherRegistrantsUsedCount;
            return(usageCountRemaining);
        }
 /// <summary>
 /// Sets the registration instance placement groups.
 /// </summary>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <param name="groups">The groups.</param>
 /// <param name="registrationTemplatePlacementId">The registration template placement identifier.</param>
 public void SetRegistrationInstancePlacementGroups(RegistrationInstance registrationInstance, List <Group> groups, int registrationTemplatePlacementId)
 {
     this.RelatedEntities.SetRelatedToSourceEntity(registrationInstance.Id, groups, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement, registrationTemplatePlacementId.ToString());
 }
Exemple #12
0
        /// <summary>
        /// Gets the multiple option single quantity fee control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionSingleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var ddl = new RockDropDownList();

            ddl.ID = "fee_" + fee.Id.ToString();
            ddl.AddCssClass("input-width-md");
            ddl.Label          = fee.Name;
            ddl.DataValueField = "Key";
            ddl.DataTextField  = "Value";
            ddl.Required       = fee.IsRequired;

            ddl.Items.Clear();
            ddl.Items.Add(new ListItem());
            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);
                var listItem            = new ListItem(string.Format("{0} ({1})", feeItem.Name, feeItem.Cost.FormatAsCurrency()), feeItem.Id.ToString());
                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            listItem.Enabled = false;
                        }

                        listItem.Text += " (none remaining)";
                    }
                    else
                    {
                        listItem.Text += $" ({usageCountRemaining} remaining)";
                    }
                }

                ddl.Items.Add(listItem);
            }

            if (setValues && feeValues != null && feeValues.Any())
            {
                var defaultFeeItemId = feeValues.Where(f => f.Quantity > 0).Select(f => f.RegistrationTemplateFeeItemId).FirstOrDefault();

                ddl.SetValue(defaultFeeItemId);
            }

            return(ddl);
        }
 public int?GetUsageCountRemaining(RegistrationInstance registrationInstance)
 {
     return(GetUsageCountRemaining(registrationInstance, null));
 }
Exemple #14
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;
        }
Exemple #15
0
        /// <summary>
        /// Gets the multiple option multiple quantity numberupdowngroup control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionMultipleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var numberUpDownGroup = new NumberUpDownGroup();

            numberUpDownGroup.ID       = "fee_" + fee.Id.ToString();
            numberUpDownGroup.Label    = fee.Name;
            numberUpDownGroup.Required = fee.IsRequired;

            numberUpDownGroup.NumberUpDownControls = new List <NumberUpDown>();

            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                var numUpDown = new NumberUpDown
                {
                    ID      = $"feeItem_{feeItem.Guid.ToString( "N" )}",
                    Label   = string.Format("{0} ({1})", feeItem.Name, feeItem.Cost.FormatAsCurrency()),
                    Minimum = 0
                };

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);

                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            numUpDown.Enabled = false;
                        }

                        numUpDown.Label  += " (none remaining)";
                        numUpDown.Maximum = currentValue;
                    }
                    else
                    {
                        numUpDown.Label  += $" ({usageCountRemaining} remaining)";
                        numUpDown.Maximum = usageCountRemaining.Value;
                    }
                }

                numberUpDownGroup.NumberUpDownControls.Add(numUpDown);

                if (setValues && feeValues != null && feeValues.Any())
                {
                    numUpDown.Value = feeValues
                                      .Where(f => f.RegistrationTemplateFeeItemId == feeItem.Id)
                                      .Select(f => f.Quantity)
                                      .FirstOrDefault();
                }
            }

            return(numberUpDownGroup);
        }
Exemple #16
0
 /// <summary>
 /// Gets the registration instance placement groups.
 /// </summary>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <returns></returns>
 public IQueryable <Group> GetRegistrationInstancePlacementGroups(RegistrationInstance registrationInstance)
 {
     return(this.RelatedEntities.GetRelatedToSourceEntity <Group>(registrationInstance.Id, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement));
 }
Exemple #17
0
 /// <summary>
 /// Sets the registration instance placement groups.
 /// </summary>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <param name="groups">The groups.</param>
 public void SetRegistrationInstancePlacementGroups(RegistrationInstance registrationInstance, List <Group> groups)
 {
     this.RelatedEntities.SetRelatedToSourceEntity(registrationInstance.Id, groups, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement);
 }
Exemple #18
0
        /// <summary>
        /// Gets the multiple option single quantity fee control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionSingleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var ddl = new RockDropDownList
            {
                ID             = "fee_" + fee.Id.ToString(),
                Label          = fee.Name,
                DataValueField = "Key",
                DataTextField  = "Value",
                Required       = fee.IsRequired
            };

            ddl.AddCssClass("input-width-md");
            ddl.Items.Clear();
            ddl.Items.Add(new ListItem());

            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                string listItemText = feeItem.Cost == 0.0M ? feeItem.Name : $"{feeItem.Name} ({feeItem.Cost.FormatAsCurrency()})";
                var    listItem     = new ListItem(listItemText, feeItem.Id.ToString());

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);
                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        listItem.Text += " (none remaining)";

                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            // Unless this should be hidden, then set to null so it isn't added.
                            if (HideWhenNoneRemaining == true)
                            {
                                listItem = null;
                            }
                            else
                            {
                                listItem.Enabled = false;
                            }
                        }
                    }
                    else
                    {
                        listItem.Text += $" ({usageCountRemaining} remaining)";
                    }
                }

                if (listItem != null)
                {
                    ddl.Items.Add(listItem);
                }
            }

            // The first item is blank. If there are no other items then return null, this will prevent the control from showing and won't count as a control when deciding to show the fee div.
            if (ddl.Items.Count == 1)
            {
                return(null);
            }

            if (setValues && feeValues != null && feeValues.Any())
            {
                var defaultFeeItemId = feeValues.Where(f => f.Quantity > 0).Select(f => f.RegistrationTemplateFeeItemId).FirstOrDefault();

                ddl.SetValue(defaultFeeItemId);
            }

            return(ddl);
        }
Exemple #19
0
        /// <summary>
        /// Gets the multiple option multiple quantity numberupdowngroup control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionMultipleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var numberUpDownGroup = new NumberUpDownGroup
            {
                ID                   = "fee_" + fee.Id.ToString(),
                Label                = fee.Name,
                Required             = fee.IsRequired,
                NumberUpDownControls = new List <NumberUpDown>()
            };

            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                string controlLabel = feeItem.Cost == 0.0M ? feeItem.Name : $"{feeItem.Name} ({feeItem.Cost.FormatAsCurrency()})";

                var numUpDown = new NumberUpDown
                {
                    ID      = $"feeItem_{feeItem.Guid.ToString( "N" )}",
                    Label   = controlLabel,
                    Minimum = 0
                };

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);

                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        numUpDown.Label  += " (none remaining)";
                        numUpDown.Maximum = currentValue;

                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            // Unless this should be hidden, then set to null so it isn't added.
                            if (HideWhenNoneRemaining == true)
                            {
                                numUpDown = null;
                            }
                            else
                            {
                                numUpDown.Enabled = false;
                            }
                        }
                    }
                    else
                    {
                        numUpDown.Label  += $" ({usageCountRemaining} remaining)";
                        numUpDown.Maximum = usageCountRemaining.Value;
                    }
                }

                if (numUpDown != null)
                {
                    numberUpDownGroup.NumberUpDownControls.Add(numUpDown);

                    if (setValues && feeValues != null && feeValues.Any())
                    {
                        numUpDown.Value = feeValues
                                          .Where(f => f.RegistrationTemplateFeeItemId == feeItem.Id)
                                          .Select(f => f.Quantity)
                                          .FirstOrDefault();
                    }
                }
            }

            // If there are no items then return null, this will prevent the control from showing and won't count as a control when deciding to show the fee div.
            if (!numberUpDownGroup.NumberUpDownControls.Any())
            {
                return(null);
            }

            return(numberUpDownGroup);
        }
        /// <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();
                    }
                }
            }
        }
 /// <summary>
 /// Gets the registration instance placement groups by placement.
 /// </summary>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <param name="registrationTemplatePlacementId">The registration template placement identifier.</param>
 /// <returns></returns>
 public IQueryable <Group> GetRegistrationInstancePlacementGroupsByPlacement(RegistrationInstance registrationInstance, int registrationTemplatePlacementId)
 {
     return(GetRegistrationInstancePlacementGroupsByPlacement(registrationInstance.Id, registrationTemplatePlacementId));
 }
        /// <summary>
        /// Deletes (detaches) the registration instance placement group for the given registration template placement ID.
        /// </summary>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="group">The group.</param>
        /// <param name="registrationTemplatePlacementId">The registration template placement identifier.</param>
        public void DeleteRegistrationInstancePlacementGroup(RegistrationInstance registrationInstance, Group group, int registrationTemplatePlacementId)
        {
            string qualifierValue = registrationTemplatePlacementId.ToString();

            this.RelatedEntities.DeleteTargetEntityFromSourceEntity(registrationInstance.Id, group, RelatedEntityPurposeKey.RegistrationInstanceGroupPlacement, qualifierValue);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupPlacementRegistrant" /> class.
 /// </summary>
 /// <param name="registrationRegistrant">The registration registrant.</param>
 /// <param name="person">The person.</param>
 /// <param name="alreadyPlacedInGroup">if set to <c>true</c> [already placed in group].</param>
 /// <param name="registrationInstance">The registration instance.</param>
 /// <param name="options">The options.</param>
 public GroupPlacementRegistrant(RegistrationRegistrant registrationRegistrant, Person person, bool alreadyPlacedInGroup, RegistrationInstance registrationInstance, GetGroupPlacementRegistrantsParameters options)
 {
     this.RegistrationRegistrant = registrationRegistrant;
     this.Person = person;
     this.AlreadyPlacedInGroup = alreadyPlacedInGroup;
     this.RegistrationInstance = registrationInstance;
     this.Options = options;
 }
 public void AddFeeControl(PlaceHolder phFees, RegistrationInstance registrationInstance, bool setValues, List <FeeInfo> feeValues)
 {
     AddFeeControl(phFees, registrationInstance, setValues, feeValues, null);
 }