Let's suppose we have a table of products, similar to this one:
| ProductId | ProductFriendlyName | ProductPrice |
|---|---|---|
| 84 | Coke can | 2 |
When a specific condition applies (the actual condition isn't really important: it could be "on every thursday", "when it is raining in Paris"), the price can be modified.
| ConditionId | AffectedProduct | OverridePrice |
|---|---|---|
| 43 | 84 | 3 |
I have thought of two solutions:
- Client side: when the client needs the price of an item an external service is used to fetch the specific price:
int getSpecificPrice(int productId){
var activeCondition = getActiveCondition(productId);
if (activeCondition != null)
{
return activeCondition.OverridePrice;
}
else
{
var prod = getProdById(productId);
return prod.ProductId;
}
}
- Database side: a view is used to fetch the data, the price the client gets is already modified to consider any external condition.
Which solution would be cleaner? Is there any other approach to consider?