Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegistrantInfo" /> class.
        /// </summary>
        /// <param name="registrant">The registrant.</param>
        /// <param name="rockContext">The rock context.</param>
        public RegistrantInfo(RegistrationRegistrant registrant, RockContext rockContext)
            : this()
        {
            if (registrant != null)
            {
                Id            = registrant.Id;
                Guid          = registrant.Guid;
                GroupMemberId = registrant.GroupMemberId;
                GroupName     = registrant.GroupMember != null && registrant.GroupMember.Group != null ?
                                registrant.GroupMember.Group.Name : string.Empty;
                RegistrationId  = registrant.RegistrationId;
                Cost            = registrant.Cost;
                DiscountApplies = registrant.DiscountApplies;
                OnWaitList      = registrant.OnWaitList;

                Person person = null;
                Group  family = null;

                if (registrant.PersonAlias != null)
                {
                    PersonId        = registrant.PersonAlias.PersonId;
                    PersonAliasGuid = registrant.PersonAlias.Guid;
                    person          = registrant.PersonAlias.Person;

                    if (person != null)
                    {
                        PersonName = person.FullName;
                        family     = person.GetFamily(rockContext);
                        if (family != null)
                        {
                            FamilyGuid = family.Guid;
                        }
                    }
                }

                if (registrant.Registration != null &&
                    registrant.Registration.RegistrationInstance != null &&
                    registrant.Registration.RegistrationInstance.RegistrationTemplate != null)
                {
                    var templateFields = registrant.Registration.RegistrationInstance.RegistrationTemplate.Forms
                                         .SelectMany(f => f.Fields);
                    foreach (var field in templateFields)
                    {
                        object dbValue = GetRegistrantValue(registrant, person, family, field, rockContext);
                        if (dbValue != null)
                        {
                            FieldValues.Add(field.Id, new FieldValueObject(field, dbValue));
                        }
                    }

                    foreach (var fee in registrant.Fees)
                    {
                        FeeValues.AddOrIgnore(fee.RegistrationTemplateFeeId, new List <FeeInfo>());
                        FeeValues[fee.RegistrationTemplateFeeId].Add(new FeeInfo(fee));
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Discounts the cost.
        /// </summary>
        /// <param name="discountPercent">The discount percent.</param>
        /// <param name="discountAmount">The discount amount.</param>
        /// <returns></returns>
        public virtual decimal DiscountedTotalCost(decimal discountPercent, decimal discountAmount)
        {
            if (OnWaitList)
            {
                return(0.0M);
            }

            var discountedCost = Cost - (DiscountApplies ? (Cost * discountPercent) : 0.0M);

            if (FeeValues != null)
            {
                foreach (var fee in FeeValues.SelectMany(f => f.Value))
                {
                    discountedCost += DiscountApplies ? fee.DiscountedCost(discountPercent) : fee.TotalCost;
                }
            }

            discountedCost -= DiscountApplies ? discountAmount : 0.0M;

            return(discountedCost > 0.0m ? discountedCost : 0.0m);
        }