c# - Should I implement business logic on a Model or a ViewModel -


when i'm processing business logic in mvvm app. should on model or viewmodel?

for example, if want re-calculate costs after asset has been re-valued, should operate on model?

is there advantage in doing on viewmodel instead?

what happens if have list of viewmodels, want translate list of models can processing? expose model property of viewmodel (and use build list of models). means view able access properties of original model

the model's purpose represent (or model) business domain. therefore, business logic definition goes in model, not viewmodel.

the job of viewmodel expose properties , fields of model, , prepare them consumption view.

for instance, picture banking application. model may represent account. perhaps model has account balance. job of model may track balance , make sure invariants maintained (such not allowing withdrawal larger balance). job of viewmodel may turn balance string used binding in view.

you want keep logic out of viewmodel possible keep code reusable , loosely coupled.