コード例 #1
0
        private DebuggerViewModel GetViewModel()
        {
            // get active visitor groups
            var user                = this.HttpContext.User;
            var allVisitorGroups    = this._visitorGroupRepository.Service.List();
            var visitorGroupHelper  = new VisitorGroupHelper(this._visitorGroupRoleRepository.Service);
            var activeVisitorGroups = allVisitorGroups
                                      .Where(x => visitorGroupHelper.IsPrincipalInGroup(user, x.Name))
                                      .Select(x => $"'{x.Name}'")
                                      .ToList();

            // compose view model
            var script = activeVisitorGroups.Any()
                ? $"console.log('Active Visitor Groups: ' + {string.Join(", ", activeVisitorGroups)});"
                : "console.log('There are no active Visitor Groups');";
            var viewModel = new DebuggerViewModel
            {
                Script = script
            };

            return(viewModel);
        }
        protected override RewardDescription Evaluate(VisitorGroupDiscountPromotion promotionData, PromotionProcessorContext context)
        {
            // get all items from the cart
            var lineItems = this.GetLineItems(context.OrderForm).ToList();

            // get any codes that the promotion applies to (check visitor group to filter)
            Guid visitorGroupGuid;

            Guid.TryParse(promotionData.VisitorGroup, out visitorGroupGuid);
            var user = HttpContext.Current.User;
            var visitorGroupHelper = new VisitorGroupHelper(this._visitorGroupRoleRepository.Service);
            var visitorGroup       = this._visitorGroupRepository.Service.Load(visitorGroupGuid);
            var isVisitorGroup     = visitorGroupHelper.IsPrincipalInGroup(user, visitorGroup.Name);
            var applicableCodes    = isVisitorGroup
                ? this._targetEvaluator.Service.GetApplicableCodes(lineItems, promotionData.Entries, true).ToList()
                : new List <string>();

            // check to see whether the promotion has been fulfilled
            var fulfillmentStatus = this._fulfillmentEvaluator.Service
                                    .GetStatusForBuyFromCategoryPromotion(applicableCodes, lineItems);

            // get redemption status
            var redemptions     = new List <RedemptionDescription>();
            var affectedEntries = context.EntryPrices.ExtractEntries(applicableCodes, 1);

            if (affectedEntries != null)
            {
                redemptions.Add(this.CreateRedemptionDescription(affectedEntries));
            }

            return(RewardDescription.CreatePercentageReward(
                       fulfillmentStatus,
                       redemptions,
                       promotionData,
                       promotionData.Percentage,
                       fulfillmentStatus.GetRewardDescriptionText(this._localizationService.Service)));
        }