i'm currently working on a project using MVVM and Entity Framework Code First Model. So i implemented IDataErrorInfo and INotifyPropertyChanged in my model classes. Now, in my viewmodel i implemented a SaveCommand and a CanSave boolean method, my question is how can i raise canexecutechanged for the whole entity and not individual properties? since my properties already implemented InotifyPropertyChanged in model.
This is my Model Class
public class Guest:ValidatableBindableClass
{
//my properties here
//implement InotifyPropertyChanged and IDataErrorInfo
}
This is my ViewModelClass:
public class AddEditGuestViewModel:BindableClass
{
private Hospede guest;
public RelayCommand SaveCommand { get; set; }
private readonly Hmsdb.HMS context = new Hmsdb.HMS();
public Hospede Guest
{
get { return guest; }
set { SetProperty(ref guest, value, propertyName: "Guest"); }
}
private void OnSave()
{
context.Hospedes.Add(Guest);
context.SaveChanges();
}
private bool CanSave()
{
return context.Entry(Guest)
.GetValidationResult().IsValid;
}
}