Hi, All
I am new to CSLA. Actually I can access child collections in parent page but how can i access child collection in child validation class.
E..g., I have a requirement based on previous data entered i have to run some validations.
Thanks,
San
I'm not quite sure what you are asking. Could you provide some more details?
Actually I have a requirement where it should trigger some validation rules.
for e.g., user can enter multiple records for a month.
Let say user entered 3 records for jan month, each record has a unique id.
On 1st record user entered age as 67 and on 2nd record there is a drop-down list which user picked 1st record unique id and entered age as 34. so I should throw and error message saying age is not equal.
Thanks!
San
I have done something similar to this. I had a scenario where the start date and end date values couldn't intersect. Don't know if my solution is the prefered way to do it. Structure of my objects is Transportation - TransportationRateList - TransportationRate. I made a object Business Rule like below. Note that it isn't a property business rule, but a rule to be used on the TransportationRate object. In the transportation Rate object I add the rule
public class DateSpansDoNotIntersectRule : BusinessRule { protected override void Execute(RuleContext context) { var target = (TransportationRate)context.Target; TransportationRateList targetList = target.Parent as TransportationRateList; DateSpan ds = new DateSpan(target.StartDate, target.EndDate); if (targetList != null) { //get list of datespans that we need to check var q = (from t in targetList where t != target && t.FreightMethod == target.FreightMethod && t.Pallet == target.Pallet && ds.Intersect(new DateSpan(t.StartDate, t.EndDate)) != null select t).FirstOrDefault(); if (q != null) context.AddErrorResult("Effective Date spans cannot intersect."); } } }
BusinessRules.AddRule(new DateSpansDoNotIntersectRule());
One of the problems with the PropertyStatus control is that it doesn't work for object Business Rules, only rules on properties.
For me to get this to work I had to expose the accessiblity of Broken Rules Collection
public IEnumerable<BrokenRule> BusinessObjectErrors { get { if (this.BrokenRulesCollection.Where(b => String.IsNullOrEmpty(b.Property)).Count() > 0) { return this.BrokenRulesCollection.Where(b => String.IsNullOrEmpty(b.Property)); } return null; } }then I bound a column to the BusinessObjectErrors and set the data template for the column<DataTemplate> <ItemsControl ItemsSource="{Binding}" Margin="4" Padding="4"> <ItemsControl.Template> <ControlTemplate TargetType="{x:Type ItemsControl}" > <ItemsPresenter/> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush="{StaticResource BorderErrorBrush}" BorderThickness="1" CornerRadius="10" Background="{StaticResource BackgroundErrorBrush}"> <StackPanel Orientation="Horizontal" Background="Transparent"> <Image Source="{StaticResource Horizon_Image_Error}" ToolTip="{Binding Path=Description}" MaxHeight="12" MaxWidth="12"/> </StackPanel> </Border> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" Orientation="Vertical" Margin="4" /> <!--Background="Yellow"--> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate>
You will also have to take into account property status changes.
I really appreciate your reponse, but i would like to get previous data through collections.
You can't have business rules on the collections themselves.
Is there any other way to implement the functionality.
-San
I haven't found another way except for what I detailed earlier in these posts.
Copyright (c) Marimer LLC