コード例 #1
0
        /// <summary>
        /// Filters the promotions.
        /// </summary>
        /// <param name="evaluationContext">The evaluation context.</param>
        /// <param name="records">The records, must be sorted in the order they are applied.</param>
        /// <returns></returns>
		public PromotionRecord[] FilterPromotions(IPromotionEvaluationContext evaluationContext, PromotionRecord[] records)
		{
            var appliedRecords = new List<PromotionRecord>();

            var groups = new Dictionary<string, string>();

            foreach (var record in records)
            {
                if (!groups.ContainsKey(record.PromotionType)) // we already have exclusive withing a current group, so ignore
                {
                    if (record.Reward.Promotion.ExclusionTypeId == (int)ExclusivityType.Group)
                    {
                        groups.Add(record.PromotionType, record.Reward.Promotion.PromotionId);
                    }

                    appliedRecords.Add(record);
                }
                else // remove the rest of promotion records unless it was generated by the applied group promotion
                {
                    if (groups.ContainsValue(record.Reward.Promotion.PromotionId))
                        appliedRecords.Add(record);
                }
            }

            return appliedRecords.ToArray();
		}
コード例 #2
0
        public void AddPromotion(
            string promoId,
            string discountType,
            double amountSize,
            string amountType,
            DateTime expiration,
            int userId,
            int?campaignId,
            DateTime created)
        {
            if (expiration == DateTime.MinValue)
            {
                expiration = DateTime.MaxValue;
            }

            var promotionCurrency = _currencyRepository.Table
                                    .FirstOrDefault(c => c.Code == amountType);

            var newPromotion = new PromotionRecord()
            {
                PromoId        = promoId,
                DiscountType   = discountType,
                AmountSize     = amountSize,
                AmountType     = amountType,
                Status         = true,
                Expiration     = expiration,
                Redeemed       = 0,
                UserId         = userId,
                CampaignId     = campaignId,
                Created        = created,
                CurrencyRecord = promotionCurrency
            };

            _promotionRepository.Create(newPromotion);
        }
コード例 #3
0
        /// <summary>
        /// Filters the promotions.
        /// </summary>
        /// <param name="evaluationContext">The evaluation context.</param>
        /// <param name="records">The records, must be sorted in the order they are applied.</param>
        /// <returns></returns>
		public PromotionRecord[] FilterPromotions(IPromotionEvaluationContext evaluationContext, PromotionRecord[] records)
		{
            // applied global promotion, set to empty at the beginning
            var appliedGlobalPromotionId = String.Empty;
            var appliedRecords = new List<PromotionRecord>();

            foreach (var record in records)
            {
                if (appliedGlobalPromotionId == String.Empty)
                {
                    if (record.Reward.Promotion.ExclusionTypeId == (int)ExclusivityType.Global)
                    {
                        // set promotion id so we can filter all the rest of promotions
                        appliedGlobalPromotionId = record.Reward.Promotion.PromotionId;
                    }

                    appliedRecords.Add(record);
                }
                else // remove the rest of promotion records unless it was generated by the applied global promotion
                {
                    if (record.Reward.Promotion.PromotionId == appliedGlobalPromotionId)
                        appliedRecords.Add(record);
                }
            }

            return appliedRecords.ToArray();
		}
コード例 #4
0
		public PromotionRecord[] FilterPromotions(IPromotionEvaluationContext evaluationContext, PromotionRecord[] records)
		{
            /*
			var retVal = promotions;
			var shipmentRewards = retVal.SelectMany(x => x.Rewards.OfType<ShipmentReward>()).ToArray();
			//Only a max relative(%) discount or absolute($). The relative (%) has a exlude the absolute ($).
			var maxShipmentReward = shipmentRewards.Where(x => x.AmountTypeId == (int)RewardAmountType.Relative)
																   .OrderByDescending(x => x.Amount)
																   .FirstOrDefault();
			if (maxShipmentReward == null)
			{
				maxShipmentReward = shipmentRewards.Where(x => x.AmountTypeId == (int)RewardAmountType.Absolute)
																	   .OrderByDescending(x => x.Amount)
																	   .FirstOrDefault();
			}
			if (maxShipmentReward != null)
			{
				//Remove all other shipment rewards from promotions
				foreach (var toRemoveReward in shipmentRewards.Where(x => x != maxShipmentReward))
				{
					toRemoveReward.Promotion.Rewards.Remove(toRemoveReward);
				}
			}

			return retVal.Where(x => x.Rewards.Count() > 0).ToArray();
             * */
            return records;
		}
コード例 #5
0
        public override void Modify(PromotionRecord record)
        {
            DbCommand command = this.Provider.GetStoredProcedure("spInsertUpdatePromotion");

            this.MapParameterIn(command, "@PA_USER_LOGIN_ID", "dev");
            this.MapParametersIn(command, record, true);
            this.Execute(command);
            this.MapParametersOut(command, record);
        }
コード例 #6
0
        public ActionResult AddPromotion(PromotionRecord model)
        {
            int currentUser = Services.WorkContext.CurrentUser.Id;

            _promotionService.AddPromotion(model.PromoId, model.DiscountType, model.AmountSize, model.AmountType, model.Expiration, currentUser, null, DateTime.Now.ToUniversalTime());
            var viewModel = new PromotionViewModel()
            {
            };

            return(RedirectToAction("MarketingCampaigns"));
        }
コード例 #7
0
        /// <summary>
        /// Create Promotion records
        /// </summary>
        /// <param name="products"></param>
        /// <param name="recList"></param>
        private void CreatePromotion(Product[] products, ref List <IRecord> recList, ref List <ulong> indexList)
        {
            //for each product...
            for (int x = 0; x < products.Length; x++)
            {
                //if the list is null skip iteration
                if (products[x].promotions == null)
                {
                    continue;
                }
                //for each promotion...
                for (int y = 0; y < products[x].promotions.Length; y++)
                {
                    //Promotion Record
                    PromotionRecord promotionRec = new PromotionRecord(indexList[x], products[x].promotions[y].type.value, products[x].promotions[y].eligibilityRequirementDescription, products[x].promotions[y].benefitDescription, products[x].promotions[y].promotionId);

                    //add to list
                    recList.Add(promotionRec);
                }
            }
        }
        private LineItem[] GetLineItemsSuitableForCatalogItemReward(PromotionRecord record)
        {
            var reward = record.Reward as CatalogItemReward;

            if (reward == null)
            {
                return(new LineItem[0]);
            }
            var entries = record.AffectedEntriesSet.Entries.ExcludeCategories(ParseStringIds(reward.ExcludingCategories))
                          .ExcludeProducts(ParseStringIds(reward.ExcludingProducts))
                          .ExcludeSkus(ParseStringIds(reward.ExcludingSkus))
                          .InCategory(reward.CategoryId)
                          .InProduct(reward.ProductId)
                          .OfSku(reward.SkuId)
                          .ToArray();

            var ids = from e in entries select e.EntryId;

            return((from l in CurrentOrderGroup.OrderForms[0].LineItems
                    where ids.Contains(l.CatalogItemId, StringComparer.OrdinalIgnoreCase)
                    select l).ToArray());
        }
コード例 #9
0
 private static void FillViewModelWithPromo(CampaignIndexViewModel viewModel, PromotionRecord promotion)
 {
     viewModel.PromoId   = promotion.PromoId;
     viewModel.PromoSize = promotion.AmountSize;
     viewModel.PromoType = promotion.AmountType;
 }
コード例 #10
0
        private async Task <TurnRecord> TurnFromPiecePositionChange(Piece pieceMoved, BoardPosition from, BoardPosition to, bool doGetPromotionSelectionIfNeeded)
        {
            TurnRecord      turn      = null;
            CaptureRecord   capture   = null;
            PromotionRecord promotion = null;
            var             move      = new MoveRecord(pieceMoved, from, to);

            Piece pieceCaptured = null;

            if ((pieceCaptured = _model.GetPieceAt(to)) != null)
            {
                capture = new CaptureRecord(pieceCaptured);
            }

            if (pieceMoved.Capabilities is PawnCapabilities)
            {
                // TODO: handle en passant if needed

                // promotion
                if (doGetPromotionSelectionIfNeeded &&
                    ((pieceMoved.Side == Side.White && to.Row == 7) ||
                     (pieceMoved.Side == Side.Black && to.Row == 0)))
                {
                    var newCapability = await _board.GetPromotionSelectionAsync();

                    promotion = new PromotionRecord(pieceMoved, newCapability);
                }
            }

            if (capture != null || promotion != null)
            {
                turn = new TurnRecord(move, capture, promotion);
            }
            else if (IsMoveCastle(move))
            {
                var kingMovedBy       = move.To.Column - move.From.Column;
                var moveDirection     = kingMovedBy / Math.Abs(kingMovedBy);
                var newCastlePosition = new BoardPosition((uint)(move.From.Column + moveDirection), move.From.Row);

                if (kingMovedBy < 0)
                {
                    var castlePosition = new BoardPosition(0, move.From.Row);
                    var castleToMove   = _model.GetPieceAt(castlePosition);
                    var secondaryMove  = new MoveRecord(castleToMove, castlePosition, newCastlePosition);
                    turn = new TurnRecord(move, secondaryMove);
                }
                else
                {
                    var castlePosition = new BoardPosition(7, move.From.Row);
                    var castleToMove   = _model.GetPieceAt(castlePosition);
                    var secondaryMove  = new MoveRecord(castleToMove, castlePosition, newCastlePosition);
                    turn = new TurnRecord(move, secondaryMove);
                }
            }
            else
            {
                turn = new TurnRecord(move);
            }

            return(turn);
        }