Этот код ниже для моего ButtonCommand
class ButtonCommand : ICommand
{
private Action<object> whatToExecute;
public ButtonCommand(Action<object> whatToExecute)
{
this.whatToExecute = whatToExecute;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
//parameter have value
whatToExecute(parameter);
}
}
И этот код ниже для моего PersonViewModel в этом классе, я получаю данные из представления и вызываю делегата, который подключается к методу Insert Method и Delete и передает их в класс ButtonCommand:
PersonType personType;
private ButtonCommand insertCommand;
private ButtonCommand deleteCommand;
public event PropertyChangedEventHandler PropertyChanged;
public PersonTypeViewModel()
{
personType = new PersonType();
insertCommand = new ButtonCommand((p)=> { Insert(PersonType); });
deleteCommand = new ButtonCommand((s) => { Delete(PersonType); });
}
public ICommand btnClickInsert
{
get
{
return insertCommand;
}
}
public ICommand btnClickDelete
{
get
{
return deleteCommand;
}
}
public void Insert(PersonType personType)
{
if(this.personType.Insert(personType) == 1)
{
MessageBox.Show("Successfull Insert");
}
PropertyChanged(this, new PropertyChangedEventArgs("GetAll"));
}
public List<PersonType> GetAll
{
get
{
return personType.GetAll();
}
}
public void Delete(PersonType personType)
{
if (this.personType.Delete(personType) == 1)
{
MessageBox.Show("Successfull Delete");
}
PropertyChanged(this, new PropertyChangedEventArgs("GetAll"));
}
этот код для моего PersonType:
public PersonType()
{
int id { get; set; }
string typeName { get; set; }
string description { get; set; }
}
в методах вставки и удаления метода значения personType не заданы
как я могу решить эту проблему?