This project has moved. For the latest updates, please go here.

CrudViewModel for BookLibrary Sample

Mar 30, 2010 at 5:28 PM

I thought to remove redundant code introducing a new abstract class "CrudViewModel"

    /// <summary>
    /// Provides common functionality for la CRUD Toolbar
    /// </summary>
    public abstract class CrudViewModel : ViewModel<IView>
    {
       private ICommand addNewCommand;
       private ICommand removeCommand;

       public CrudViewModel(IView view)
            : base(view)
        {
           
        }

       public ICommand AddNewCommand
        {
            get { return addNewCommand; }
            set
            {
                if (addNewCommand != value)
                {
                    addNewCommand = value;
                    RaisePropertyChanged("AddNewCommand");
                }
            }
        }

        public ICommand RemoveCommand
        {
            get { return removeCommand; }
            set
            {
                if (removeCommand != value)
                {
                    removeCommand = value;
                    RaisePropertyChanged("RemoveCommand");
                }
            }
        }
    }

 

 

Then each EntityListViewModel inherits from CrudViewModel the CRUD methods...

 public class BookListViewModel : CrudViewModel {

etc..

}

Coordinator
Mar 31, 2010 at 6:33 PM

Good idea to introduce a new abstract class that handles the Add- and RemoveCommand.

Thanks for your feedback.