I have several ViewModels all doing partly the same: del/add/export etc documents. At the moment the code to call these methods lives in the viewmodels. So I have to copy/paste it... When I put that code in a DocumentHelper class I have it only one time, but do you see any reason against calling database methods from a Helper class?
An emphatic YES, you should move your code to a helper class.
I am a strong believer in the Pragmatic Programmer's Don't Repeat Yourself principle. It is one you should strive to follow, as well. By copy-and-pasting the code, it makes making changes an obnoxious pain, since you have to find every single place you copied that code and change it there. The copy-and-paste technique crushes any agility you might have had and makes refactoring a nightmare.
I wanted to comment supporting Travis G's comment but I ran out of room - hence this 'answer'.
You want to be careful how you arrange your system regarding dependencies; keep in mind how re-usable you want things to be. If the DocHelper references the model then anytime you want to re-use the Dochelper (say in another app) then you will have to bring across the model as well.
Two possible approaches:
Things that are "common" in the context of the model are located in the model assembly.
MyApp.Model // including Model Helpers
MyApp.Common // contains generic helpers
In terms of references, Model
could reference Common
- but not the other way around.
Things that are "common" in the context of the model are located in a separate assembly - and that assembly is a dedicated Model "helper"; things that are truly generic should be in a separate assembly, e.g:
MyApp.Model
MyApp.ModelHelper // Model helpers are kept separate
MyApp.Common // contains generic helpers
In this case, Model
would reference ModelHelper
, and Model
and/or ModelHelper
could reference Common
.