Reputation: 109
I'm developing a simple expense tracker app, organized by categories, in C# and entity framework.
My entities are:
I am using MVVM, and separating concerns: I have a business layer, a data access layer, and a view/view model layer.
I want to display on my first page a list of categories with the total amount spent on every category for a specific month.
Where should I integrate the calculation of these amounts for every category?
Q1 : On my business layer my category object has a "SummedExpensesAmount" field, so I thought I would call from my business layer the DAL so I would fill this field for every category and for a specific month. Is it ok to do this operation on the Business layer? Can it actually be considered business related or should I migrate that to the DAL and design my Database differently?
Second approach: Should I have similar object on DAL on Business, and do all the sorting on the ViewModel layer, meaning having business methods returning total amount for specific categories and period, calling it in a loop and filling a custom Category view model.
What are the pros/cons of each approach?
Upvotes: 0
Views: 147
Reputation: 16409
In my opinion, any approach is OK based on your use-case.
I will personally discard point 3 above. I will take the decision based on whether I am calculating totals in SQL Query or not. Based on that, I will choose 1 or 2 from above.
Upvotes: 1