Robust billing system design. Am I going completely in the wrong direction?

I am developing a hotel / billing registration application in ASP.Net using an entity structure. When it comes to creating an account for the registrant, my client has a lot of stupid criteria. Instead of a billing system for one bed (fairly standard ..), the client may be charged a different amount depending on their age, the specific dates they attend, the type of room (double bed, single bed, etc.) or a conference, on which they are present, or all four ...

Here is my chart: http://s8.postimg.org/w8nxh8qlh/abstraction.jpg

As a relatively young coder, I feel like I'm missing something, somewhere along the Rule table. What I'm trying to do allows the administrator to create any number of ConditionalStatements ("Age> 5" or "Age <10", where "Age" is Statement.Value, '>' is Condition.Value, and "5" is this is ConditionalStatement.Value) and bind any number of them together, thus creating a "Rule". Then the administrator will associate the rule with various RateSchedules, and then the application will be able to generate an account for any client registered for the stay.

I feel that I am on the right track and that most of this solution will work in every way that I need, but something does not seem to be right. I have two questions related to the creation of the "Rules".

  • What am I doing wrong, how far does the β€œrule design” go? It feels wrong for me to generate a new RuleSet.ID every time the administrator wants to create a new rule. Should I do this programmatically? Should I completely rethink this rule process?

  • From an Entity Framework / scaffolding point of view, what's the best way for me to add new rules in db? Default scaffolding allows me to insert one row at a time, but to create a rule, I need to associate RuleSet.ID with several ConditionalStatement.IDs, but I cannot figure out how to do this intuitively with EF scaffolding ..

Any pointers in the right direction are highly appreciated! Thanks:)

EDIT: I ended up redesigning based on the answers to my question, but during the study I came across the Microsoft business rules engine: http://msdn.microsoft.com/en-us/library/aa561216.aspx as well as the math expression evaluator: http : //ncalc.codeplex.com/ Just in case, someone else will find this question in the future, and these links may help. Thanks for helping everyone!

+6
source share
1 answer

Modeling your domain in a database is usually bad practice. The database should be a detail, and all your logic should be in code. To do this, you must design to find out the requirements from the client and create a domain on top of it. At this point, saving them will be very simple.

For example, imagine the abstract PricingRule class and many different implementations, such as AgePricingRule, DatePricingRule, RoomTypePricingRule. Then your Bill object can take PricingRules and apply them and get the final price.

The amount of complexity of the data that needs to be stored will be trivial, only some configuration for pricing rules.

-1
source

Source: https://habr.com/ru/post/945627/


All Articles