why not be able to delete objects when expanded?

This commit is contained in:
2024-04-30 10:16:51 +02:00
parent 6394876adf
commit 8bb931b886
2 changed files with 21 additions and 2 deletions

View File

@@ -16,10 +16,18 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
public Employee SelectedEmployee public Employee SelectedEmployee
{ {
get { return selectedEmployee; } get { return selectedEmployee; }
set { SetProperty(ref selectedEmployee, value); (UpdateEmployeeCommand as RelayCommand).NotifyCanExecuteChanged(); } set
{
SetProperty(ref selectedEmployee, value);
(UpdateEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
(DeleteEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
(GetSubordinatesCommand as RelayCommand).NotifyCanExecuteChanged();
}
} }
public ICommand UpdateEmployeeCommand { get; set; } public ICommand UpdateEmployeeCommand { get; set; }
public ICommand DeleteEmployeeCommand { get; set; }
public ICommand GetSubordinatesCommand { get; set; }
public static bool IsInDesignMode public static bool IsInDesignMode
{ {
@@ -34,7 +42,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
if (!IsInDesignMode) if (!IsInDesignMode)
{ {
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/Employee", "hub"); Employees = new RestCollection<Employee>("http://localhost:5000/", "api/GetSubordinates", "hub");
UpdateEmployeeCommand = new RelayCommand(() => UpdateEmployeeCommand = new RelayCommand(() =>
{ {
@@ -44,6 +52,15 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
return SelectedEmployee != null; return SelectedEmployee != null;
}); });
DeleteEmployeeCommand = new RelayCommand(() =>
{
Employees.Delete(SelectedEmployee.ID);
},
() =>
{
return SelectedEmployee != null;
});
} }
} }
} }

View File

@@ -74,6 +74,8 @@
<UniformGrid Rows="2" Grid.Row="1"> <UniformGrid Rows="2" Grid.Row="1">
<Button Content="Edit selected" Command="{Binding UpdateEmployeeCommand}"/> <Button Content="Edit selected" Command="{Binding UpdateEmployeeCommand}"/>
<Button Content="Delete selected" Command="{Binding DeleteEmployeeCommand}"/>
<Button Content="Get subordinates"/>
<Button Content="Create new" Click="CreateNewEmployee" /> <Button Content="Create new" Click="CreateNewEmployee" />
</UniformGrid> </UniformGrid>
</Grid> </Grid>