/// <summary>
        /// ((PromotionEvaluationContext)x).IsItemInCategory(CategoryId, ExcludingCategoryIds, ExcludingProductIds)
        /// </summary>
        public override bool IsSatisfiedBy(IEvaluationContext context)
        {
            var result = false;

            if (context is PromotionEvaluationContext promotionEvaluationContext)
            {
                result = promotionEvaluationContext.IsItemInCategory(CategoryId, ExcludingCategoryIds.ToArray(), ExcludingProductIds.ToArray());
            }

            return(result);
        }
Exemplo n.º 2
0
        public linq.Expression <Func <IEvaluationContext, bool> > GetExpression()
        {
            linq.ParameterExpression paramX = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp     = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(DisplayTemplateEvaluationContext));
            var methodInfo = typeof(DisplayTemplateEvaluationContext).GetMethod("ItemIsInCategory");
            var methodCall = linq.Expression.Call(castOp, methodInfo, linq.Expression.Constant(SelectedCategoryId)
                                                  , ExcludingCategoryIds.GetNewArrayExpression()
                                                  , ExcludingProductIds.GetNewArrayExpression());
            var retVal = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(methodCall, paramX);

            return(retVal);
        }
        /// <summary>
        /// ((PromotionEvaluationContext)x).GetCartItemsQuantity(ExcludingCategoryIds, ExcludingProductIds) > NumItem
        /// </summary>
        public override bool IsSatisfiedBy(IEvaluationContext context)
        {
            var result = false;

            if (context is PromotionEvaluationContext promotionEvaluationContext)
            {
                var quantity = promotionEvaluationContext.GetCartItemsQuantity(ExcludingCategoryIds.ToArray(), ExcludingProductIds.ToArray());
                result = UseCompareCondition(quantity, NumItem, NumItemSecond);
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// ((PromotionEvaluationContext)x).GetCartTotalWithExcludings(ExcludingCategoryIds, ExcludingProductIds) > SubTotal
        /// </summary>
        public override bool Evaluate(IEvaluationContext context)
        {
            var result = false;

            if (context is PromotionEvaluationContext promotionEvaluationContext)
            {
                var quantity = promotionEvaluationContext.GetCartTotalWithExcludings(ExcludingCategoryIds.ToArray(), ExcludingProductIds.ToArray());
                result = UseCompareCondition(quantity, SubTotal, SubTotalSecond);
            }

            return(result);
        }
Exemplo n.º 5
0
        public override linq.Expression <Func <IEvaluationContext, bool> > GetExpression()
        {
            var paramX     = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp     = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(PromotionEvaluationContext));
            var methodInfo = typeof(PromotionEvaluationContext).GetMethod("GetItemsQuantity");
            var methodCall = linq.Expression.Call(castOp, methodInfo, ExcludingCategoryIds.GetNewArrayExpression(),
                                                  ExcludingProductIds.GetNewArrayExpression(), ExcludingSkuIds.GetNewArrayExpression());
            var numItem  = linq.Expression.Constant(NumItem);
            var binaryOp = ExactlyLeast.IsExactly ? linq.Expression.Equal(methodCall, numItem) : linq.Expression.GreaterThanOrEqual(methodCall, numItem);

            var retVal = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(binaryOp, paramX);

            return(retVal);
        }
        /// <summary>
        /// ((PromotionEvaluationContext)x).IsItemInCategory(CategoryId, ExcludingCategoryIds, ExcludingProductIds)
        /// </summary>
        /// <returns></returns>
        public linq.Expression <Func <IEvaluationContext, bool> > GetConditionExpression()
        {
            var paramX     = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp     = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(PromotionEvaluationContext));
            var methodInfo = typeof(PromotionEvaluationContextExtension).GetMethod("IsItemInCategory");

            var methodCall = linq.Expression.Call(null, methodInfo, castOp, linq.Expression.Constant(CategoryId), ExcludingCategoryIds.GetNewArrayExpression(),
                                                  ExcludingProductIds.GetNewArrayExpression());
            var retVal = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(methodCall, paramX);

            return(retVal);
        }
Exemplo n.º 7
0
        /// <summary>
        /// ((PromotionEvaluationContext)x).GetCartTotalWithExcludings(ExcludingCategoryIds, ExcludingProductIds) > SubTotal
        /// </summary>
        /// <returns></returns>
        public override linq.Expression <Func <IEvaluationContext, bool> > GetConditionExpression()
        {
            var paramX         = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp         = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(PromotionEvaluationContext));
            var subTotal       = linq.Expression.Constant(SubTotal);
            var subTotalSecond = linq.Expression.Constant(SubTotalSecond);
            var methodInfo     = typeof(PromotionEvaluationContextExtension).GetMethod("GetCartTotalWithExcludings");

            var leftOperandExpression = linq.Expression.Call(null, methodInfo, castOp, ExcludingCategoryIds.GetNewArrayExpression(),
                                                             ExcludingProductIds.GetNewArrayExpression());
            var rightOperandExpression       = linq.Expression.Constant(SubTotal);
            var rightSecondOperandExpression = linq.Expression.Constant(SubTotalSecond);

            var result = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(GetConditionExpression(leftOperandExpression, rightOperandExpression, rightSecondOperandExpression), paramX);

            return(result);
        }
        /// <summary>
        /// ((PromotionEvaluationContext)x).IsAnyLineItemTotal(LineItemTotal, LineItemTotalSecond, CompareCondition,  ExcludingCategoryIds, ExcludingProductIds)
        /// </summary>
        /// <returns></returns>
        public override linq.Expression <Func <IEvaluationContext, bool> > GetConditionExpression()
        {
            var paramX              = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp              = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(PromotionEvaluationContext));
            var lineItemTotal       = linq.Expression.Constant(LineItemTotal);
            var lineItemTotalSecond = linq.Expression.Constant(LineItemTotalSecond);
            var methodInfo          = typeof(PromotionEvaluationContextExtension).GetMethod("IsAnyLineItemExtendedTotalNew");
            var compareCondition    = linq.Expression.Constant(CompareCondition);

            var methodCall = linq.Expression.Call(null, methodInfo, castOp, lineItemTotal, lineItemTotalSecond, compareCondition, ExcludingCategoryIds.GetNewArrayExpression(),
                                                  ExcludingProductIds.GetNewArrayExpression());

            var retVal = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(methodCall, paramX);

            return(retVal);
        }
Exemplo n.º 9
0
        public override linq.Expression <Func <IEvaluationContext, bool> > GetExpression()
        {
            var paramX          = linq.Expression.Parameter(typeof(IEvaluationContext), "x");
            var castOp          = linq.Expression.MakeUnary(linq.ExpressionType.Convert, paramX, typeof(PromotionEvaluationContext));
            var lineItemTotal   = linq.Expression.Constant(LineItemTotal);
            var methodInfo      = typeof(PromotionEvaluationContext).GetMethod("IsAnyLineItemTotal");
            var equalsOrAtLeast = ExactlyLeast.IsExactly ? linq.Expression.Constant(true) : linq.Expression.Constant(false);
            var methodCall      = linq.Expression.Call(castOp, methodInfo, lineItemTotal, equalsOrAtLeast, ExcludingCategoryIds.GetNewArrayExpression(),
                                                       ExcludingProductIds.GetNewArrayExpression(), ExcludingSkuIds.GetNewArrayExpression());

            var retVal = linq.Expression.Lambda <Func <IEvaluationContext, bool> >(methodCall, paramX);

            return(retVal);
        }