lundi 17 février 2020

Technical design problem: should it be in DAL, Business, or ViewModel layer?

I'm developing a simple expense tracker app, organized by categories, in C# and entity framework.

My entities are:

Catgory: Id, Name Expense: Id,Name, Date, CategoryId

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 ammount spent on every category for a specific month.

Where should I integrate the calculation of these ammounts for every category? Q1 : On my business layer my category object has a "SummedExpensesAmmount" 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 ammount 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?

Aucun commentaire:

Enregistrer un commentaire