I just can't get a grasp on 4.0 rules system. There are two simple rules that calculate values. They both do get executed, but Total2Property does not get refreshed in DataGrid, not until I double click the cell.
So, please can someone tell me what is wrong here? I tried chaining rules, but with same results. How should I write rules in this situation?
UPDATE: Seems that only primary property gets updated?
Thanks
protected override void AddBusinessRules()
{
BusinessRules.ProcessThroughPriority = 1;
base.AddBusinessRules();
...
BusinessRules.AddRule(new Csla.Rules.CommonRules.Dependency(PriceProperty, Total1Property));
BusinessRules.AddRule(new Csla.Rules.CommonRules.Dependency(QuantityProperty, Total1Property));
BusinessRules.AddRule(new Total1(Total1Property, PriceProperty, QuantityProperty) { Priority = 2 });
BusinessRules.AddRule(new Csla.Rules.CommonRules.Dependency(TaxProperty, Total1Property));
BusinessRules.AddRule(new Total2(Total1Property, Total2Property, TaxProperty) { Priority = 3 });
}
public class Total1 : Csla.Rules.BusinessRule
{
IPropertyInfo PriceProperty;
IPropertyInfo QuantityProperty;
public Total1(IPropertyInfo Total1Property, IPropertyInfo PriceProperty, IPropertyInfo QuantityProperty)
: base(Total1Property)
{
if (InputProperties == null) InputProperties = new List<IPropertyInfo>() { Total1Property, PriceProperty, QuantityProperty };
this.PriceProperty = PriceProperty;
this.QuantityProperty = QuantityProperty;
}
protected override void Execute(RuleContext context)
{
context.AddOutValue(Math.Round((decimal)context.InputPropertyValues[this.PriceProperty] * (decimal)context.InputPropertyValues[this.QuantityProperty], 2));
}
}
public class Total2 : Csla.Rules.BusinessRule
{
IPropertyInfo Total2Property;
IPropertyInfo TaxProperty;
public Total2(IPropertyInfo Total1Property, IPropertyInfo Total2Property, IPropertyInfo TaxProperty)
: base(Total1Property)
{
if (InputProperties == null) InputProperties = new List<IPropertyInfo>() { Total1Property, Total2Property, TaxProperty };
AffectedProperties.Add(Total2Property);
this.Total2Property = Total2Property;
this.TaxProperty = TaxProperty;
}
protected override void Execute(RuleContext context)
{
context.AddOutValue(Total2Property, (decimal)context.InputPropertyValues[PrimaryProperty] + (decimal)context.InputPropertyValues[this.TaxProperty]);
}
}
Copyright (c) Marimer LLC