Problem on Validation

Posts   
 
    
EddieKX
User
Posts: 2
Joined: 17-Jul-2006
# Posted on: 31-Aug-2006 04:35:40   

I have an OrderEntity which hold the general information (e.g. : OrderNo, TotalPrice...) each OrderEntity have a child collection for OrderDetailEntity (e.g. : OrderEntity.OrderDetailCollection) which hold the detail information about the order (e.g. : ItemNo, Qty, UnitPrice, Discount...)

While the detail's unit price is updated, the related order's total price should also be updated. The case is, there exists the validation on the validator for OrderEntity.TotalPrice which check the OrderEntity.TotalPrice cannot over certain limit. The whole update process should be rollbacked when the validation error is fired.

Since the validation error is fired from TotalPrice, not from UnitPrice, the UnitPrice can still be updated while the TotalPrice is remain unchanged.

Does anyone have idea to code this kind of checking so that the validation error can be returned to UnitPrice, not to TotalPrice?

thx.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Aug-2006 07:05:37   

You can validate the UnitPrice field, and then add or subtract the difference between the UnitPrice new value and its current value to the TotalPrice of the related entity.

Or You can use EntityValidation to set the total price on saving the entity or when Validate is called explicitly. (You may validate the entity wafter you set a unit price)

Or use a business code to change the value of the total price when the value of the unit price changes. Or to calculate the total value before saving the entity.