Exemple #1
0
 public void Compile(IRuleDefinitionContext context)
 {
     foreach (var rule in _rules)
     {
         rule.Compile(context);
     }
 }
Exemple #2
0
        public override void Define(IRuleDefinitionContext ruleContext)
        {
            //var newOrders = ruleContext.OnNew<Order>();
            //var updatedOrders = ruleContext.OnChange<Order>().Select(orderFact => (orderFact.Context, orderFact.Fact));

            _disposable = ruleContext.OnNew <Order>()
                          .Where(orderFact => orderFact.Fact.IsOpen)
                          .Where(orderFact => !orderFact.Fact.IsDiscounted)
                          .Subscribe(orderFact =>
            {
                var context = orderFact.Context;
                var order   = orderFact.Fact;

                var customer = context.Get <Customer>(order.Customer.Id);

                if (customer.IsPreferred)
                {
                    order.ApplyDiscount(10.0);
                    context.Update(order, nameof(Order.PercentDiscount));
                }
            });
        }
Exemple #3
0
 public abstract void Define(IRuleDefinitionContext context);
Exemple #4
0
 public void Compile(IRuleDefinitionContext context)
 {
     Define(context);
 }