IsDirty, HasDirtyModel..again

Topics: Questions
Aug 27, 2013 at 8:20 AM
Hello, please help me get it right:
My model is designed like this: Batch -> Requests, Productions..
The entities derive only from IDataErrorInfo, INotifyPropertyChanging, INotifyPropertyChanged
However the DAL is smart about saving an entity: all modifications to a Request are also persisted when a Batch is saved.
So in my BatchView I expose the Batch properties and all related Requests/Productions as separate user controls. On the 'ActionBar' of the BatchView I have the Save/Restore buttons. The actual command execution seems clear: I just save, or reload from the back-end.
Now what I am missing is how to properly manage their visibility in regards to the state of the Batch and all underlying ViewModels.
Coordinator
Aug 28, 2013 at 3:38 PM
I don't understand your issue. You want to check if any child is dirty?
Aug 28, 2013 at 4:30 PM
Yes, the parent-batch or any of its children. Do I have to keep a reference between the viewmodels or is it better to create a IsDirty field inside the entities, or can I somehow use catel and its IsDirty and HasDirtyModel properties, that seem to be True and False no matter what I try.
Coordinator
Aug 28, 2013 at 5:32 PM
A viewmodel has an IsDirty property. You can use that. You can get all children of a viewmodel via the IViewModelManager.

Best is of course that the entities know that they are dirty, but if that is not possible, you can also manage this via the IsDirty on the view model OR use your own properties for that.
Aug 28, 2013 at 6:15 PM
How can I use the VM IsDirty property? It always gets dirty right after init. I also tried exposing the model using explicit mode but again the property becomes true straight after init. And HasDirtyModel..what function is suppose to set this property? I'm sorry, I probably should have gotten the sources by now.. :)
Coordinator
Aug 28, 2013 at 6:34 PM
Note that the IsDirty is for all vm properties, probably not only for your model. What you can do is introduce a IsModelDirty or something like that. For the other stuff, indeed check the source, that's what I have to do as well ;-)