コード例 #1
0
        /// <summary>
        /// Gets the fee item count remaining.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        /// A dictionary of fee item unique identifier keys with the number of
        /// items remaining as the value. The value will be <c>null</c> if there
        /// is no configured limit.
        /// </returns>
        public Dictionary <Guid, int?> GetFeeItemCountRemaining(RegistrationContext context)
        {
            var feeItems = context.RegistrationSettings.Fees.SelectMany(f => f.FeeItems);
            var map      = feeItems.ToDictionary(fi => fi.Guid, fi => fi.MaximumUsageCount);

            var service        = new RegistrationRegistrantFeeService(Context as RockContext);
            var quantitiesUsed = service.Queryable()
                                 .AsNoTracking()
                                 .Where(rf =>
                                        rf.RegistrationRegistrant.Registration.RegistrationInstanceId == context.RegistrationSettings.RegistrationInstanceId &&
                                        rf.RegistrationTemplateFeeItem.MaximumUsageCount.HasValue)
                                 .Select(f => new
            {
                f.Quantity,
                f.RegistrationTemplateFeeItem.Guid
            })
                                 .ToList();

            foreach (var quantityUsed in quantitiesUsed)
            {
                var qtyRemaining = Math.Max(0, (map.GetValueOrNull(quantityUsed.Guid) ?? 0) - quantityUsed.Quantity);
                map[quantityUsed.Guid] = qtyRemaining;
            }

            return(map);
        }
コード例 #2
0
        /// <summary>
        /// Gets the registration template fee report.
        /// </summary>
        /// <param name="registrationInstanceId">The registration instance identifier.</param>
        /// <returns></returns>
        public IEnumerable <TemplateFeeReport> GetRegistrationTemplateFeeReport(int registrationInstanceId)
        {
            var qry = new RegistrationRegistrantFeeService(this.Context as RockContext).Queryable();

            qry = qry.Where(a => a.RegistrationRegistrant.Registration.RegistrationInstanceId == registrationInstanceId);

            var result = qry.Select(a => new TemplateFeeReport
            {
                RegistrationId   = a.RegistrationRegistrant.RegistrationId,
                RegistrationDate = a.RegistrationRegistrant.Registration.CreatedDateTime ?? DateTime.MinValue,
                RegisteredByName = a.RegistrationRegistrant.Registration.FirstName + " " + a.RegistrationRegistrant.Registration.LastName,
                RegistrantPerson = a.RegistrationRegistrant.PersonAlias.Person,
                RegistrantId     = a.RegistrationRegistrantId,
                FeeName          = a.RegistrationTemplateFee.Name,
                FeeItemOption    = a.Option,
                FeeItem          = a.RegistrationTemplateFeeItem,
                Quantity         = a.Quantity,
                Cost             = a.Cost
            }).ToList();

            return(result);
        }
コード例 #3
0
        /// <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);
        }